title: Unable to run a command from php to linux
body: <p>I was trying to run a command from PHP to my Linux server but I'm having some trouble with one command:
  This is the script:</p>
  <pre><code>&lt;?php
    $output=null;
    $retval=null;
    exec('speedtest -L -f, --format=json 2&gt;&amp;1', $output, $retval);
    echo &quot;Returned with status $retval and output:\n&quot;;
    print_r($output);
  ?&gt;
  </code></pre>
  <p>The output is:</p>
  <pre><code>Returned with status 134 and output: 
         Array ( [0] =&gt; terminate called after throwing an instance of 'std::logic_error' 
                 [1] =&gt; what(): basic_string::_M_construct null not valid 
                 [2] =&gt; Aborted (core dumped))
  </code></pre>
  <p>The user that runs the script is: www-data
  if I try to run it directly on the terminal it works.</p>
  <pre><code>command from terminal: sudo -u www-data speedtest -L
  output: {&quot;type&quot;:&quot;serverList&quot;,&quot;timestamp&quot;:&quot;2021-02-23T09:20:51Z&quot;,&quot;servers&quot;:[{&quot;id&quot;:4302,&quot;name&quot;:&quot;Vodafone IT&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speedtest.vodafone.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:7839,&quot;name&quot;:&quot;Fastweb SpA&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;spd-pub-mi-01-01.fastwebnet.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:11427,&quot;name&quot;:&quot;EOLO&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;test.eolo.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:1434,&quot;name&quot;:&quot;CWNET&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speedtest.cheapnet.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:3667,&quot;name&quot;:&quot;TIM SpA&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speedtestmi1.telecomitalia.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:8211,&quot;name&quot;:&quot;CDLAN S.R.L.&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speedtest.cdlan.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:11675,&quot;name&quot;:&quot;Italiaonline Supernap&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speedtest-supernap.italiaonline.it&quot;,&quot;port&quot;:8080},{&quot;id&quot;:20551,&quot;name&quot;:&quot;Optima Italia&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;mi-speedtest.optimaitalia.com&quot;,&quot;port&quot;:8080},{&quot;id&quot;:26415,&quot;name&quot;:&quot;P-Lab&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;speed.speedymilan.net&quot;,&quot;port&quot;:8080},{&quot;id&quot;:19177,&quot;name&quot;:&quot;Seeweb&quot;,&quot;location&quot;:&quot;Milan&quot;,&quot;country&quot;:&quot;Italy&quot;,&quot;host&quot;:&quot;ookla-mil.seeweb.it&quot;,&quot;port&quot;:8080}]}
  </code></pre>
  <p>If I run another command it works perfectly:</p>
  <pre><code>&lt;?php
    $output=null;
    $retval=null;
    exec('whoami', $output, $retval);
    sleep(1);
    echo &quot;Returned with status $retval and output:\n&quot;;
    print_r($output);
  ?&gt;
  </code></pre>
  <p>The output is:</p>
  <pre><code>Returned with status 0 and output: Array ( [0] =&gt; www-data )
  </code></pre>
  <p>Do you guys have any suggestions?</p>