[英]PHP prints out a buffer string into web-page on certain circuntances?
我不知道该怎么解释,但是,我来试试看。
此问题涉及2台服务器,本地服务器和托管服务器。 两台服务器都运行相同的PHP版本7.0 [几乎具有相同的配置]。 和2个控制器动作。 问题出在$app->run($input, $out);
从下面的代码。
我的控制器中有该动作:
/**
* @Route("/testJson")
*/
public function testJsonAction() {
$app = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->get("kernel"));
$app->setAutoExit(false);
$opt = array("command" =>
"doctrine:generate:entity",
"--entity" => "GuervylEditorBundle:TestOnline",
"--fields" => "kl:string");
$input = new \Symfony\Component\Console\Input\ArrayInput($opt);
$out = new \Symfony\Component\Console\Output\BufferedOutput();
$app->run($input, $out);
$out->fetch();
return new JsonResponse(\json_encode(["a" => "b", "c" => "d"]));
}
从本地和托管服务器调用此操作将返回"{"a":"b","c":"d"}"
,并显示Content-Type
application/jsonContent-Type
application/jsonContent-Type
很棒,这是预期的结果。
application/json
现在,问题来了:
上面几乎相同的代码,将其设置在另一个类中,我从另一个控制器操作中调用它,该操作通过不同类的4个方法来调用具有上面代码的方法[callCommand]
这是实现代码的方法:
public function callCommand($cmd, $opt, &$mykernel = null) {
if ($mykernel == NULL) {
$mykernel = new myKernel("dev", false, __DIR__ . "/../Resources/template_2.8/app");
}
$app = new \Symfony\Bundle\FrameworkBundle\Console\Application($mykernel);
$app->setAutoExit(false);
$opt = array("command" => $cmd) + $opt;
$input = new \Symfony\Component\Console\Input\ArrayInput($opt);
$out = new \Symfony\Component\Console\Output\BufferedOutput();
$app->run($input, $out);
}
从其他控制器操作中,我最后还返回了一个json内容。 由于代码太大,我无法显示代码。
当我从本地主机调用该控制器动作时,我得到了JSON内容和Content-Type: application/json
,这很好。
但是从托管服务器调用它,我会得到一些额外的文本,例如:
Entity generation
created ./src/Guervyl/EditorBundle/Entity/TestCase.php
> Generating entity class src/Guervyl/EditorBundle/Entity/TestCase.php: OK!
> Generating repository class src/Guervyl/EditorBundle/Repository/TestCaseRepository.php: OK!
Everything is OK! Now get to work :).
调用$app->run($input, $out);
时从控制台输出的文本$app->run($input, $out);
。 之后,我得到设置的HTTP标头,然后是json内容。 内容类型也是application/x-httpd-php5
。
该错误仅在特定的托管服务器上发生。 我测试了其他托管服务器,其代码在本地服务器上的工作方式类似于。
我的问题是为什么我在该特定主机上收到错误消息? 我可以从PHP.ini中进行更改以进行修复吗? 因为我确实需要在该主机上托管我的网站,因为它为我提供了我需要的强大功能,而其他功能则没有,或者它们太昂贵了。
好吧,在调试代码之后,我注意到发生了错误,因为我没有设置--no-interaction
选项。 因此,如果没有该选项,则当没有为实体指定任何字段时,Symfony将等待输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.