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::kill ( int $pid [, int $signal_no ] )
the pid of child process
the signal to send, the default is SIGTERM
if sends signal successfully, it returns TRUE, otherwise it returns FALSE.
Send signal to the child process.
<?php
$child_num = 3;
$child_processes = [];
for($i = 1; $i <= $child_num; $i++)
{
$process = new OpenSwoole\Process(function($worker){
echo "the pid of child process is " . $worker->pid . "\n";
$worker->name("php child process");
sleep(rand(20, 60));
}, FALSE);
$res = $process->useQueue(0, 2);
$pid = $process->start();
$child_processes[(string)$pid] = $process;
}
sleep(5);
foreach($child_processes as $pid => $child_process)
{
$ret = OpenSwoole\Process::kill($pid);
var_dump($ret);
$ret = OpenSwoole\Process::wait();
var_dump($ret);
}