title: exec and shell_exec not working in php
body: <p>I am having problems with exec and shell_exec i have looked at every post on here and cant seem to find the problem. the code i am using :</p>
  
  <pre><code>chdir('/');
  $handle = shell_exec("/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2&gt;&amp;1");
  echo $handle .":". gettype($handle) . "\n";
  $read = fread($handle, 2096);
  echo $read;
  </code></pre>
  
  <p>the screen looks like this:</p>
  
  <pre><code>...
  X-Powered-By: PHP/5.3.21 Content-type: text/html (repeated about 100 times)
  X-Powered-By: PHP/5.3.21 Content-type: text/html 
  PHP Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2&gt;&amp;1' in /home/donor/public_html/batch/test.php on line 4 X-Powered-By: PHP/5.3.21 Content-type: text/html 
  Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2&gt;&amp;1' in /home/donor/public_html/batch/test.php on line 4
  :boolean PHP Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6 
  Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6
  :string PHP Warning: fread() expects parameter 1 to be resource, string given in /home/donor/public_html/batch/test.php on line 6 (repeated another 100ish times)
  </code></pre>
  
  <p>PHP safemode is turned off. Permissions for the folder the files is in .../batch/ and the /usr/bin/php are both set to 755. The user for all files are the same except for php (php file user is root). Nothing is disabled in the php.ini file. Works fine in the CLI. and simple commands such as <code>whoami</code> and <code>ls</code> work fine. I feel like i am missing something</p>
  
  <p>EDIT:
  tried what cpattersonv1 said and got:</p>
  
  <pre><code>X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html 2540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  </code></pre>
  
  <p>EDIT 2: does anyone know why it looks like it is trying the command more then once? </p>
  
  <p>EDIT 3: I put the command inside a .sh file and tried to run that. works in CLI but again does not work from php</p>
  
  <pre><code>chdir('/');
  $handle = exec(". /home/donor/public_html/batch/test.sh");
  </code></pre>
  
  <p>I get the same output;</p>