From: mikan at playcollective dot com
Operating system: Linux (RedHat 7.2)
PHP version: 4.3.0
PHP Bug Type: Scripting Engine problem
Bug description: Background script stalls after 300 seconds
I've been developping a daemon-script that runs in the background, after
being spawned from the parent script.
i use an:
// we are parent. spawn child and exit.
$sock = fsockopen (getenv("SERVER_NAME"), 80);
if(!$sock){
echo "ERROR: $errstr ($errno)\n";
} else {
if(socket_set_blocking($sock, false)){
fputs($sock, "GET ".getenv("REQUEST_URI")."?child=1 HTTP/1.1\n");
fputs($sock, "Host: ".getenv("SERVER_NAME")." \n");
fputs($sock, "Connection: close\n\n");
fclose($sock);
} else {
echo "ERROR: blocking socket. execution halted.\n";
exit();
}
}
to spawn the child process (fork is not supported on the system this
script is developed for). this code essentially opens a non-blocking
socket to itself, with the variable child=1, and exits. the child process
is now running.
this child process starts with:
set_time_limit (0);
ignore_user_abort(true);
to be able to run "forever"...
after this it goes into an eternal while loop.
now, the problem is the following: if nothing happens within the loop
(e.g. no output is produced, the script only checks and sleeps) the script
halts (but doesn't die/exit) after exactly 300 seconds. the process still
exists in the process list on the server.
if the script produces an non-fatal error within every 300 seconds, it
continues running happily for hours and hours and hours.
i tried outputting a "boo" message using echo "boo"; every ten seconds,
and that didn't seem to work. i tried flushing after echoing, that didn't
work either. now i free a mysql-result that doesn't exist, and that DOES
work!
--
Edit bug report at http://bugs.php.net/?id=22452&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22452&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22452&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22452&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22452&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22452&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22452&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22452&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22452&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22452&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22452&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22452&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22452&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22452&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22452&r=gnused