<?php /** * Scenes: * Monitor the status queue order form of communication * A process announced two other processes scramble to queue */ // set the main process name echo 'main process the above mentioned id:' posix_getpid ().. PHP_EOL ; cli_set_process_title('php_main'); // 1, for changing the child process monitor data $ Process1 = new new \ Swoole \ Process ( function (\ Swoole \ Process $ Process ) { @ cli_set_process_title ( 'php_child'); $ Process -> name ( 'php_child1' ); $ PDO = new new \ the PDO ( 'MySQL: Host = MySQL; dbname = Test', 'the root', 'csh.aptx4869 #' ); the while ( to true ) { $ Statement = $ PDO -> Query ( 'SELECT * WHERE is_pay from `order` = 0. 1 and is_notice Order by ID desc =' ); $ Data = $ Statement -> FETCH (the PDO :: FETCH_ASSOC) ; IF ( $ data ) { // posted to the message queue data $ Process -> Push ( 'php_child1 transmission'. $ data [ 'CLIENT_NAME'] 'paid'. ); $ PDO -> Exec ( ' `Update Order WHERE is_notice. 1 SET = `ID = '. $ Data [ID' ' ]); } sleep(3); } } , To false , SOCK_STREAM, to true ); // start message queue as interprocess communication $ Process1 -> useQueue (2 ); echo 'child process ID. 1:'. $ Process1 . -> Start () value is PHP_EOL ; // 2, this sub-process for sending messages $ Process2 = new new \ Swoole \ Process ( function (\ Swoole \ Process $ Process ) { $ Process -> name ( 'php_child2' ); the while ( to true ) { // from the queue extracting data $ the orderInfo = $ Process -> POP (); IF ( $ the orderInfo ) { echo $ the orderInfo ; echo 'php_child2 send mail'. value is PHP_EOL ; } sleep(3); } } , To false , SOCK_STREAM, to true ); $ Process2 -> useQueue (2 ); echo 'child process ID 2:'. $ Process2 -> Start (). Value is PHP_EOL ; // 3, this sub-process for sending messages $ process3 = new new \ Swoole \ Process ( function (\ Swoole \ Process $ Process ) { $ Process -> name ( 'php_child3' ); the while ( to true ) { // from the queue extracting data $ the orderInfo = $ Process -> POP (); IF ( $ the orderInfo ) { echo $ the orderInfo ; echo 'php_child3 send mail'. value is PHP_EOL ; } sleep(3); } } , To false , SOCK_STREAM, to true ); $ process3 -> useQueue (2 ); echo 'child process ID. 3:'. $ Process3 -> Start (). Value is PHP_EOL ; while (true) { sleep(3); } //\Swoole\Process::wait(); // Process when using as a parent to monitor, manage to create a child process, the parent must register the signal SIGCHLD execution wait to exit the process, otherwise it will become a zombie process when the child process exits Swoole \ Process :: Signal (SIGCHLD, function ( $ signo ) { // to false non-blocking mode the while ( $ RET = \ Swoole \ Process :: the wait ( to false )) { var_dump ( $ RET ); } });