本文整理汇总了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";
}
}
示例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;
}
示例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());