Welcome to the Linux community forum and interact with 2 million technical staff. Go to the Internet and check the PHP multi-process control instance written by a freshman user. Share this article: declare (ticks1 ); functionsigHandler ($ signal) {echoachildexitedn;} pcntl_signal (SIGCHLD, sigHandler, false); ech
Welcome to the Linux community forum and interact with 2 million technical staff> go to the Internet and check the PHP multi-process control instance written by a freshman user. Share it with you: declare (ticks = 1); function sigHandler ($ signal) {echo "a child exited \ n" ;}pcntl_signal (SIGCHLD, sigHandler, false); ech
Welcome to the Linux community forum and interact with 2 million technicians>
Let's take a look at the PHP multi-process control instance written by a freshman online. Let's share it with you:
Declare (ticks = 1 );
Function sigHandler ($ signal)
{
Echo "a child exited \ n ";
}
Pcntl_signal (SIGCHLD, sigHandler, false );
Echo "this is". posix_getpid (). PHP_EOL;
For ($ I = 0; $ I <3; $ I ++)
{
$ Pid = pcntl_fork ();
If ($ pid =-1)
{
Echo 'fork failed'. PHP_EOL;
}
Else if ($ pid)
{
}
Else
{
$ Pid = posix_getpid ();
Echo 'child '. $ pid. ''. time (). PHP_EOL;
Sleep (rand (2, 5 ));
Echo 'child '. $ pid. 'done'. time (). PHP_EOL;
Exit (0 );
}
}
Do
{
$ Pid = pcntl_wait ($ status );
Echo 'child quit'. $ pid. PHP_EOL;
} While ($ pid> 0 );
Echo 'parent done'. PHP_EOL;