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::exec ( string $exec_file , array $args )
New name of the process
The arguments passing into the exec_file
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.
<?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);