0

I use a CLI script to do some stuff. Today i want to adapte it to show me results on my browser rather than on temrinal. It works everytime perfectly when called called from terminal but not when i call it from exec php command WHEN there is a call on the doctrine Cursor::toArray. See bellow :

it executes the following lines of code :

        $parses=$dm->createQueryBuilder("App\Document\Parse")
                ->field('positions.website')->equals($name)
                ->getQuery()->execute();
        /* @var $parses Doctrine\ODM\MongoDB\Cursor */

        $details=[];




        foreach($parses as $parse){

            /* some other things */
        }


        echo json_encode($details);

when called form terminal (php cli.php find parses -site test.com) it return me a nice json document.

But now I want to show it on a browser. Then i do a little script (http accessable) calling 'exec("php cli.php find parses -site test.com")' . And it returns me nothing. (also tryed shell_exec ; also tryed with other scripts : they work)

Now i delete the foreach loop. I got the following code :

        $parses=$dm->createQueryBuilder("App\Document\Parse")
                ->field('positions.website')->equals($name)
                ->getQuery()->execute();
        /* @var $parses Doctrine\ODM\MongoDB\Cursor */

        $details=[];

        echo json_encode($details);

When i call it from exec : it returns me a nice empty json string

(Remember that each case still works when i call it directly from terminal)

Now i try to call ->toArray() on the doctrine cursor :

        $parses=$dm->createQueryBuilder("App\Document\Parse")
                ->field('positions.website')->equals($name)
                ->getQuery()->execute();
        /* @var $parses Doctrine\ODM\MongoDB\Cursor */

        $details=[];

        $parses->toArray();

        echo json_encode($details);

It returns nothing when i call it from exec or shell exec, but it returns a well "array(0) {}" when called from terminal itself.

It tryed other script with exec and shell exec, they all work and do good return, only when they dont use Doctrine cursor toArray

4

1 回答 1

0

当您从终端运行 PHP 脚本时,它会在运行用户的许可下运行。当您在 Web 服务器上运行 PHP 脚本时,它会以服务器进程的权限运行。

检查运行脚本的用户是否有权访问 Web 目录中与运行服务器的用户相同的文件。

另外,您是否打开error_reporting并检查了error_log文件?

于 2013-05-28T08:08:13.520 回答