OpenSwoole\Process::__construct

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\\Process::__construct ( callable $callback [, boolean $redirect_stdin_and_stdout [, int $pipe_type ]] )

Parameters

callback

The callback function executed in the child process. The Swoole Process exits when the function exits.

redirect_stdin_and_stdout

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.

pipe_type

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.

Return

Description

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.

Example

<?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();
Last updated on September 1, 2022