note 94338 added to function.pcntl-fork
| From: | Tony at osu1 dot php dot net | Date: | Thu, 29 Oct 2009 11:05:56 +0000 |
| Subject: | note 94338 added to function.pcntl-fork | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162233@lists.php.net to get a copy of this message | ||
If you want to execute some code after your php page has been returned to the user. Try something
like this -
function index()
{
function shutdown() {
posix_kill(posix_getpid(), SIGHUP);
}
// Do some initial processing
echo("Hello World");
// Switch over to daemon mode.
if ($pid = pcntl_fork())
return; // Parent
ob_end_clean(); // Discard the output buffer and close
fclose(STDIN); // Close all of the standard
fclose(STDOUT); // file descriptors as we
fclose(STDERR); // are running as a daemon.
register_shutdown_function('shutdown');
if (posix_setsid() < 0)
return;
if ($pid = pcntl_fork())
return; // Parent
// Now running as a daemon. This process will even survive
// an apachectl stop.
sleep(10);
$fp = fopen("/tmp/sdf123", "w");
fprintf($fp, "PID = %s\n", posix_getpid());
fclose($fp);
return;
}
----
Server IP: 69.147.83.197
Probable Submitter: 122.104.130.236
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-fork.php
Edit -- https://master.php.net/note/edit/94338
Del: integrated -- https://master.php.net/note/delete/94338/integrated
Del: useless -- https://master.php.net/note/delete/94338/useless
Del: bad code -- https://master.php.net/note/delete/94338/bad+code
Del: spam -- https://master.php.net/note/delete/94338/spam
Del: non-english -- https://master.php.net/note/delete/94338/non-english
Del: in docs -- https://master.php.net/note/delete/94338/in+docs
Del: other reasons-- https://master.php.net/note/delete/94338
Reject -- https://master.php.net/note/reject/94338
Search -- https://master.php.net/manage/user-notes.php