本文整理汇总了PHP中swoole_process::useQueue方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_process::useQueue方法的具体用法?PHP swoole_process::useQueue怎么用?PHP swoole_process::useQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swoole_process
的用法示例。
在下文中一共展示了swoole_process::useQueue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback_function
<?php
$workers = [];
$worker_num = 2;
for ($i = 0; $i < $worker_num; $i++) {
$process = new swoole_process('callback_function', false, false);
$process->useQueue();
$pid = $process->start();
$workers[$pid] = $process;
//echo "Master: new worker, PID=".$pid."\n";
}
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
while (true) {
$recv = $worker->pop();
echo "From Master: {$recv}\n";
}
sleep(2);
$worker->exit(0);
}
while (true) {
/**
* @var $process swoole_process
*/
$pid = array_rand($workers);
$process = $workers[$pid];
$process->push("hello worker[{$pid}]\n");
sleep(1);
}
示例2: spawnCustomWorker
private function spawnCustomWorker($worker_name, $config)
{
$process = new \swoole_process(function (\swoole_process $worker) {
$recv = $worker->pop();
$worker_config = unserialize($recv);
extract($worker_config);
$name = isset($this->serverConfig['server']['worker_process_name']) ? $this->serverConfig['server']['worker_process_name'] : 'ypf:swoole-worker-%d';
$processName = sprintf("{$name}:%s", 0, $worker_name);
\swoole_set_process_name($processName);
self::getInstance()->disPatch($config['action'], array('worker_name' => $worker_name));
}, false, false);
$process->useQueue();
$pid = $process->start();
$this->worker_pid[] = $pid;
$process->push(serialize(array('pid' => $pid, 'worker_name' => $worker_name, 'config' => $config)));
if ($pid > 0) {
echo "starting worker : {$worker_name} [ OK ]\n";
} else {
echo "starting worker : {$worker_name} [ FAIL ] '" . \swoole_strerror(swoole_errno()) . "' \n";
}
}