Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\\Process::__construct ( callable $callback [, boolean $redirect_stdin_and_stdout [, int $pipe_type ]] )
The callback function executed in the child process. The Swoole Process exits when the function exits.
If $redirect_stdin_stdout
is TRUE
, the output of child process will be written to the the pipe of parent process, the child process read the pipe as input.
The default communication mode is blocking.
0
Don't create the pipe
1
Create the SOCK_STREAM
pipe
2
Create the SOCK_DGRAM
pipe.
If $redirect_stdin_stdout
is TRUE
, this parameter is 1
by default.
Create a child process with the callback function executed in the child process, optionally redirect standard I/O to the pipe between parent process and child process.
When the parent process is stopped, the child processes receives CLOSE event from the pipe.
<?php
$process = new OpenSwoole\Process(function($process){
echo "The pid of child process is " . $process->pid . "\n";
echo "The FD of pipe is " . $process->pipe . "\n";
$process->write("hello");
}, TRUE);
$process->start();
usleep(100);
echo $process->read();