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


PHP swoole_process::push方法代码示例

本文整理汇总了PHP中swoole_process::push方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_process::push方法的具体用法?PHP swoole_process::push怎么用?PHP swoole_process::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swoole_process的用法示例。


在下文中一共展示了swoole_process::push方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: callback_function

    //$process->daemon(true);
    $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
    $cnt = 0;
    while ($cnt < 2) {
        // 如果队列里没有数据,则pop方法阻塞等待
        $recv = $worker->pop();
        echo "From Master: {$recv}\n";
        $cnt++;
    }
    sleep(1);
    $worker->exit(0);
}
foreach ($workers as $pid => $process) {
    $process->push("hello worker[{$pid}]\n");
}
foreach ($workers as $pid => $process) {
    $process->push("hello2 worker[{$pid}]\n");
    //sleep(1);
}
for ($i = 0; $i < $worker_num; $i++) {
    $ret = swoole_process::wait();
    $pid = $ret['pid'];
    unset($workers[$pid]);
    echo "Worker Exit, PID=" . $pid . PHP_EOL;
}
开发者ID:silentred,项目名称:learning-path,代码行数:31,代码来源:queue.php

示例3: callback_function

<?php

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);
}
$process = new swoole_process('callback_function', false, false);
$process->useQueue();
$bytes = 0;
foreach (range(1, 10) as $i) {
    $data = "hello worker[{$i}]\n";
    $bytes += strlen($data);
    $process->push($data);
}
echo "bytes={$bytes}\n";
var_dump($process->statQueue());
开发者ID:noikiy,项目名称:swoole-src,代码行数:23,代码来源:msgqueue2.php


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