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\Pool->on('start', callback $callback)
The event name
callback function
if success, it returns TRUE, otherwise it returns FALSE.
Executue the callback function when the Process Pool is started.
<?php
$workerNum = 10;
$pool = new OpenSwoole\Process\Pool($workerNum);
$pool->on('start', function() {
echo "Process Pool is started\n";
});
$pool->on("WorkerStart", function ($pool, $workerId) {
echo "Worker#{$workerId} is started\n";
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$key = "key1";
while (true) {
$msgs = $redis->brpop($key, 2);
if ( $msgs == null) continue;
var_dump($msgs);
}
});
$pool->on("WorkerStop", function ($pool, $workerId) {
echo "Worker#{$workerId} is stopped\n";
});
$pool->start();