當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。