note 25739 added to function.pcntl-fork
| From: | guy at bhaktiandvedanta dot com | Date: | Thu, 03 Oct 2002 19:17:58 +0000 |
| Subject: | note 25739 added to function.pcntl-fork | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37633@lists.php.net to get a copy of this message | ||
For Windows users and everybody that doesn't have PCNTL installed (like me...), This is a way
to do fork on a script. This script doesn't have to be used to call to the same script, it can
also call another script. For example, a different script that does logging work on the server. The
"ignore_user_abort" is neccessary only when calling to the same script. The use of sleep
here is just to show some activity.
<?
// fork example
ignore_user_abort(true);
if (!isset($child)) {
// parent process
$fp = fsockopen("www.mysite.com", 80);
fputs($fp, "GET /fork.php?child=yes HTTP/1.1\n");
fputs($fp, "Host: www.mysite.com \n");
fputs($fp, "Connection: close\n\n");
$buf = fgets($fp,12);
fclose($fp);
for ($i=0; $i<10; $i++) {
flush();
sleep(5);
echo "<br>Parent process continues";
}
} else {
// child process
$tag = "child process file";
$write = fopen("files/fork.log", "w");
fwrite ($write, $tag);
fclose($write);
}
?>
Guy Laor
--
http://www.php.net/manual/en/function.pcntl-fork.php
http://master.php.net/manage/user-notes.php?action=edit+25739
http://master.php.net/manage/user-notes.php?action=delete+25739
http://master.php.net/manage/user-notes.php?action=reject+25739