开启多个进程来处理消息队列中的数据 ``` <?php require_once 'vendor/autoload.php'; use Pheanstalk\Pheanstalk; $p = new Pheanstalk('127.0.0.1', 11300); $workNum = 4; $pool = new \Swoole\Process\Pool($workNum); $pool->on('WorkerStart', function ($pool, $workerId) use ($p) { echo 'WorkerStart' . PHP_EOL; echo 'workerId:' . $workerId . PHP_EOL; try { //监听test管道,忽略default管道 $job = $p->watch('test')->ignore('default')->reserve(); $data = json_decode($job->getData(), true); //打印任务中的数据 print_r($data); //最后删除任务,表示任务处理完成 $p->delete($job); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; } }); $pool->start(); ```