yii2-webshell icon indicating copy to clipboard operation
yii2-webshell copied to clipboard

Getting "Content-Type: application/json; charset=UTF-8" output

Open Deele opened this issue 9 years ago • 0 comments

I could not get this module to reply something useful. All I get is Content-Type: application/json; charset=UTF-8 response.

At first, I was not providing correct yiiScript value, but afterwards I changed it to correct one (tested it via ssh), but still, I'm getting strange result and I don't know what is the cause.

To debug this issue, I did a little rewrite of DefaultController::runConsole() command (using code from AssetConverter::runCommand()) and made it into:

    protected function runConsole($command)
    {
        $command = Yii::getAlias($this->module->yiiScript) . ' ' . $command;
        $descriptor = [
            1 => ['pipe', 'w'],
            2 => ['pipe', 'w'],
        ];
        $pipes = [];
        $proc = proc_open($command, $descriptor, $pipes, $basePath);
        $stdout = stream_get_contents($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        foreach ($pipes as $pipe) {
            fclose($pipe);
        }
        $status = proc_close($proc);

        $command_d = \yii\helpers\VarDumper::dumpAsString($command);
        $stdout_d = \yii\helpers\VarDumper::dumpAsString($stdout);
        $stderr_d = \yii\helpers\VarDumper::dumpAsString($stderr);
        if ($status === 0) {
            Yii::trace("Command $command_d ran successfully:\nSTDOUT:\n$stdout_d\nSTDERR:\n$stderr_d", __METHOD__);
        } elseif (YII_DEBUG) {
            throw new \yii\base\Exception("Command '$command_d' failed with exit code $status:\nSTDOUT:\n$stdout_d\nSTDERR:\n$stderr_d");
        } else {
            Yii::error("Command '$command_d' failed with exit code $status:\nSTDOUT:\n$stdout_d\nSTDERR:\n$stderr_d", __METHOD__);
        }

        return [$status, $stdout];
    }

And I got this output in debug console:

Command 'php -c php.ini -f ../yii ' ran successfully:
STDOUT:
'Content-Type: application/json; charset=UTF-8

'
STDERR:
''

Deele avatar Sep 08 '15 07:09 Deele