Multi-process can be said that php is much worse than java in this regard. it is fun to find a PHP multi-process instance. let's take a look at it. the instance code is as follows: & lt ;? Php $ cmdsarray (a, B, c, d
Multi-process can be said that php is much worse than java in this regard. it is fun to find a PHP multi-process instance. let's take a look at it. the instance code is as follows:
- $ Cmds = array (a, B, c, d );
- Foreach ($ cmds as $ cmd ){
- $ Pid = pcntl_fork ();
- If ($ pid =-1 ){
- Exit ("pid fork error ");
- }
- If ($ pid) {// master process segment to control the number of sub-processes
- Static $ max = 0;
- $ Max ++;
- If ($ max> = 5 ){
- Pcntl_wait ($ status); // blocks the parent process until the child process ends.
- $ Max --;
- }
- } Else {// sub-process execution command
- $ Pid = posix_getpid ();
- Echo "$ pid ---- $ neural NN ";
- Exit (0 );
- }
- }
- ?>