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