Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine ODM Calling ->toArray on a Cursor causes CLI script called by exec to do a void return (only on exec/shell_exec call)
    text
    copied!<p>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 : </p> <p>it executes the following lines of code :</p> <pre><code> $parses=$dm-&gt;createQueryBuilder("App\Document\Parse") -&gt;field('positions.website')-&gt;equals($name) -&gt;getQuery()-&gt;execute(); /* @var $parses Doctrine\ODM\MongoDB\Cursor */ $details=[]; foreach($parses as $parse){ /* some other things */ } echo json_encode($details); </code></pre> <p>when called form terminal (php cli.php find parses -site test.com) it return me a nice json document.</p> <p>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)</p> <p>Now i delete the foreach loop. I got the following code :</p> <pre><code> $parses=$dm-&gt;createQueryBuilder("App\Document\Parse") -&gt;field('positions.website')-&gt;equals($name) -&gt;getQuery()-&gt;execute(); /* @var $parses Doctrine\ODM\MongoDB\Cursor */ $details=[]; echo json_encode($details); </code></pre> <p>When i call it from exec : it returns me a nice empty json string</p> <p>(Remember that each case still works when i call it directly from terminal)</p> <p>Now i try to call ->toArray() on the doctrine cursor :</p> <pre><code> $parses=$dm-&gt;createQueryBuilder("App\Document\Parse") -&gt;field('positions.website')-&gt;equals($name) -&gt;getQuery()-&gt;execute(); /* @var $parses Doctrine\ODM\MongoDB\Cursor */ $details=[]; $parses-&gt;toArray(); echo json_encode($details); </code></pre> <p>It returns nothing when i call it from exec or shell exec, but it returns a well "array(0) {}" when called from terminal itself.</p> <p>It tryed other script with exec and shell exec, they all work and do good return, only when they dont use Doctrine cursor toArray</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload