swoole_process::__construct

创建子进程

int swoole_process::__construct(mixed $function, $redirect_stdin_stdout = false, $create_pipe = true);
  • $process对象在销毁时会自动关闭管道,子进程内如果监听了管道会收到CLOSE事件
  • 1.7.22或更高版本允许设置管道的类型,默认为SOCK_STREAM流式
  • 参数$create_pipe为2时,管道类型将设置为SOCK_DGRAM

在子进程中创建swoole_server

可以在swoole_process创建的子进程中swoole_server服务器程序,但为了安全必须在$process->start创建进程后,调用$worker->exec执行server的代码。

<?php
$process = new swoole_process('callback_function', true);
$pid = $process->start();

function callback_function(swoole_process $worker)
{
    $worker->exec('/usr/local/bin/php', array(__DIR__.'/swoole_server.php'));
}

swoole_process::wait();