PHP implements parallel multi-process operations (daemon can be used ). As follows: Copy the code as follows: ** entry function * saves this file as ProcessOpera. php * and runs usrlocalphpbinphpProcessOpera. phpnbsp in terminal. * view the process as follows:
The code is as follows:
/**
* Entry functions
* Save this file as ProcessOpera. php
* Run/usr/local/php/bin/php ProcessOpera. php &
* View the process ps aux | grep php
*/
ProcessOpera ("runCode", array (), 8 );
/**
* Run Code
*/
Function runCode ($ opt = array ()){
// Code to be run in the daemon
}
/**
* $ Func is the name of the function for the sub-process to execute specific things.
* $ Opt is in the format of $ func parameter array
* $ Number of child processes whose pNum is fork
*/
Function ProcessOpera ($ func, $ opts = array (), $ pNum = 1 ){
While (true ){
$ Pid = pcntl_fork ();
If ($ pid =-1 ){
Exit ("pid fork error ");
}
If ($ pid ){
Static $ execute = 0;
$ Execute ++;
If ($ execute> = $ pNum ){
Pcntl_wait ($ status );
$ Execute --;
}
} Else {
While (true ){
// Somecode
$ Func ($ opts );
Sleep (1 );
}
Exit (0 );
}
}
}
The handler code is as follows:/*** entry function ** saves this file as ProcessOpera. php * runs/usr/local/php/bin/php ProcessOpera in terminal. php nbsp; * view the process...