I' m trying to run a php script in background using exec().
I have a browser request to eventtest.php, which contains:
<?php
exec("/usr/local/bin/php -q event1.php &");
die();
?>
event1.php has:
<?php
error_log("initiate event1", LOG_FILE);
die();
?>
the result is that the log entry is never generated if eventtest.php is requested, but works fine if event1.php is requested directly.
While eventtest.php is running, i see stuff like this from ps -aux, repeated many times. Any ideas what is going wrong? Is there a better way to initiate a background php process. I am running this on a shared hosting environment on Linux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
<myuser> 13899 15.0 0.2 15620 5892 ? S 17:24 0:00 /usr/local/bin/php -q event1.php
<myuser> 13927 3.0 0.0 0 0 ? Z 17:24 0:00 [sh <defunct>]
<myuser> 13938 0.0 0.2 15624 5892 ? S 17:24 0:00 /usr/local/bin/php -q event1.php
Thanks for your help
UPDATE:
Tried a slightly different exec() in eventtest.php:
exec("/usr/local/bin/php event1.php > /dev/null 2>&1");
and requested it once. Got this in the log file:
[20060411 17:30:13] ERR_DEBUG: initiate event1
[20060411 17:30:35] ERR_DEBUG: initiate event1
[20060411 17:30:54] ERR_DEBUG: initiate event1
Altought clearly i dont' have any kind of loop anywhere. Tried it again a few seconds later - nothing logged this time.