Posted by Colin McKinnon on 09/24/06 15:54
NC wrote:
> Jonah Bishop wrote:
>>
>> But the PHP manual entry for the system() function call
>> indicates the following:
>>
>> "Note: If you start a program using this function and want
>> to leave it running in the background, you have to make
>> sure that the output of that program is redirected to a file
>> or some other output stream or else PHP will hang until
>> the execution of the program ends."
>>
>
> There are at least two ways of dealing with this issue:
>
> 1. Redirect the script's output into a file:
>
> system("php myscript.php & > myscriptlog.txt");
> system("php myscript.php & >> myscriptlog.txt");
>
<snip>
almost right.
>
> 2. Buffer the output at the beginning of the script and
> discard it at the end:
>
> @ob_start();
> // the script goes here...
> @ob_end_clean();
>
wrong - this leaves stdout bound to the same file as the parent process so
will be ineffective.
Since the parent process must wait for a sig child, simply redirecting the
output is not a very clean solution. Really you want the new process to run
in a seperate session - its possible to this with fork() and
posix_setsid(), but a much simpler solution is to hand it off to daemon
like 'at':
`echo /usr/bin/php -q $my_php_script | at now`
C.
[Back to original message]
|