当前位置: 首页>>代码示例>>PHP>>正文


PHP swoole_process::useQueue方法代码示例

本文整理汇总了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);
}
开发者ID:liangkwok,项目名称:Swoole,代码行数:31,代码来源:msgqueue.php

示例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";
     }
 }
开发者ID:millken,项目名称:ypf,代码行数:21,代码来源:Swoole.php


注:本文中的swoole_process::useQueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。