swoole_process

  • swoole_process
swoole_process ( ' file path of execution ' , ' the desired file parameter ' ); // execute an external script using the Process-swoole 
swoole_process__construct (callback, redirect_stdin_stdout, whether to create a process communication pipe) 
parameters redirect_stdin_stdout subprocess is true the results are not returned to the screen, false output to the screen 
swoole_process :: the wait () // after the program is finished, the child recovered
  • Thereby one example http server with swoole_http_server
<?php
    $server = new swoole_http_server('127.0.0.1',9502);
    $server->on('request',function($request,$response){
        $response->end("there is a game of love");
});
    $server->start();
?>
  • Swoole_http_server process to achieve a swoole_process object management (file name: myhttpserver.php)
<? PHP
 // Each process has a process ID 
$ SW = new new swoole_process (function (swoole_process SW $) { 
    $ SW -> Exec ( ' / usr / bin / PHP7 ' ., [__ DIR__ ' /../myhttpserver /myhttpserver.php ' ]); 
}, to false ); 
$ PID = $ sw-> Start (); 
echo $ pid.PHP_EOL; 
swoole_process :: the wait (); # wait after finished running, sub-process recycling
  • In linux terminal switches to a position where the program calls the run php script swprocess.php
It is a script file as shown below swprocess.php instantiated swoole_process process that is $ pid = $ sw-> start () to return the $ pid

  • ps aux | grep swprocess.php
This code is used to view the parent process runs swprocess.php process information, and can be seen, the process number is 12430 12431 (swprocess.php script open period swoole_process) of

  • Role pstree -p 13430 is a branch of the command to view the process

  • ps -asf |grep myhttpserver 
myhttpserver Here is the script swprocess.php in turn swoole_http_server child process execution ($ sw-> exec ()), which is running the process of myhttpserver.php

 

Guess you like

Origin www.cnblogs.com/saintdingspage/p/10984643.html