System function to run in background

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I have the following line of PHP code:

$ret_val = system("PHP myscript.php $param1 $param2 >> output.txt &");

Obviously the intention is to run a PHP file in the background
async'ly. This works 100% perfect on one server; running the script in
the background without errors. On another server the above line runs
the command immediately rather than in the background. Output is still
redirected OK and no errors are reported.

Does anyone know of a situation that might cause the above code wait
for the child process to finish before continuing? The file was copied
from one server to the other without any modifications. Furthor, both
servers are identical in software. One was literally imaged from the

The only difference might be the file permissions. I created some
folders on both machines but I think on one of them I sudo'd to root to
create a folder and on the other I was logged in as a user (so CHOWN
might differ). In both cases though PHP has read/write access (no
errors were reported and identical script output is produced). The
permissions in question are those on the myscript.php and on the
output.txt file produced.

The PHP manual says nothing about file permissions affecting the
ability for a target script to run in the background. Any thoughts?
Should I be redirecting errout as well (e.g. 2>>errors.txt)? Maybe an
error is being reported on the second server and that is why PHP is
waiting? I can't see how PHP can know in advance that an error is going
to happen before it starts running the script in the background though.

PS: The process control functions (e.g. fork) are not enabled so
running external scripts is limited to SYSTEM and EXEC. The issue at
hand is that myscript.php is generating a report based on some very
lengthy mysql queries and typically runs for 20-30 minutes. When PHP
waits for the script to finish the client always times out which is far
from graceful.

Thanks for any insight you can offer!


Site Timeline