note 25739 deleted from function.pcntl-fork by sniper
| From: | sniper@php.net | Date: | Mon, 14 Jul 2003 02:22:32 +0000 |
| Subject: | note 25739 deleted from function.pcntl-fork by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52057@lists.php.net to get a copy of this message | ||
Note Submitter: guy@bhaktiandvedanta.com
----
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