Swoole\Process::__construct

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\\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 Swoole\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 August 31, 2022