簡體   English   中英

PHP在某些情況下會在網頁上打印出緩沖字符串?

[英]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/json
Content-Type
application/json
Content-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM