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
OpenSwoole Process can be attached and managed by OpenSwoole Server with addProcess API.
OpenSwoole Process can be used to replace PHP pcntl
extension. Compare with PHP pcntl
, OpenSwoole Process provides more features:
You can use Process Pool or Process Manager if you like to manage a group of daemon processes and not attaching to an OpenSwoole Server.
OpenSwoole\Process::__construct
OpenSwoole\Process->start
OpenSwoole\Process->name
(deprecated)OpenSwoole\Process->exec
OpenSwoole\Process->write
OpenSwoole\Process->useQueue
OpenSwoole\Process->statQueue
OpenSwoole\Process->freeQueue
OpenSwoole\Process->push
OpenSwoole\Process->pop
OpenSwoole\Process->close
OpenSwoole\Process->exit
OpenSwoole\Process->kill
OpenSwoole\Process->wait
OpenSwoole\Process->daemon
OpenSwoole\Process->signal
OpenSwoole\Process->alarm
OpenSwoole\Process->setAffinity
<?php
$process = new OpenSwoole\Process(function($worker){
echo "the pid of child process is " . $worker->pid . "\n";
echo "the file descriptor of pipe is " . $worker->pipe . "\n";
$res = $worker->write("Hello main process\n");
var_dump(strlen("Hello main process\n"));
var_dump($res);
$worker->name("php child process");
}, FALSE);
$process->start();
usleep(100);
echo $process->read();