OpenSwoole\Process::exec ( string $exec_file , array $args )

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

Declaration

<?php OpenSwoole\Process::exec ( string $exec_file , array $args )

Parameters

exec_file

New name of the process

args

The arguments passing into the exec_file

Return

Description

Execute native Linux command:

The process will be replaced by the Linux command process, but the pipe to the parent process will be kept.

If the communication between the parent process and the child process, the redirection of stdin and stdout has to be enabled.

Example

<?php
// textexec.php
$fd = fopen('php://stdin', 'r');
$res = fread($fd, 123);
echo "the message from main process" . $res;
<?php
// parent process
$process = new OpenSwoole\Process(function($process){
    //execute the external program
    $process->exec("/usr/bin/php", array('./testexec.php'));
}, TRUE); // enable the redirection of stdin and stdout

$process->start();

//Inter-Process Communication Of main process and child process by stdin and stdout

$process->write("hello child process from main process");

$res = $process->read();

var_dump($res);
Last updated on September 1, 2022