Php compile time, need to add -enable-pcntl, and is recommended only run in CLI mode, do not run the WEB server environment.
The following PHP to achieve multi-process simple test code:
code show as below:
<? PHP DECLARE (ticks = 1 ); $ bWaitFlag = FALSE ; // / whether to wait for the end of the process $ intNum = 10; // total / process $ PIDS = Array (); // / PID process array echo ( "Start \ n-" ); for ( $ I = 0; $ I < $ intNum ; $ I ++ ) { $ PIDS [ $ I ] = pcntl_fork (); // / generating sub-process, but apart from the current line under test run code, and data information does not inherit the parent process IF (! $ PIDS [ $ i ]) { // the child process code segment _start $ STR = "" ; SLEEP (5+ $ I ); for ( $ J = 0; $ J < $ I ; $ J ++) { $ STR =. "*" ; } echo " $ I . ->" Time . () " $ STR \ n-" ; Exit (); // the child process code segment _END } } IF ( $ bWaitFlag ) { for ( $ I = 0; $ I < $ intNum ; $ I ++) { pcntl_waitpid($pids[$i], $status, WUNTRACED); echo "wait $i -> " . time() . "\n"; } } echo ("End\n"); ?>