本文整理汇总了PHP中Worker::queue方法的典型用法代码示例。如果您正苦于以下问题:PHP Worker::queue方法的具体用法?PHP Worker::queue怎么用?PHP Worker::queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worker
的用法示例。
在下文中一共展示了Worker::queue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
* Created by PhpStorm.
* User: Jenner
* Date: 2015/8/19
* Time: 14:32
*/
declare (ticks=1);
require dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
error_reporting(E_ALL);
class Worker extends \Jenner\SimpleFork\Process
{
public function run()
{
while (true) {
$res = $this->queue()->get(1);
if ($res !== false) {
echo $this->getPid() . ":" . $res . PHP_EOL;
}
//usleep(100000);
}
}
}
$queue = new \Jenner\SimpleFork\Queue\SystemVMessageQueue(1, "/tmp/simple-fork-test.ipc");
$worker_1 = new Worker();
$worker_1->queue($queue);
$worker_2 = new Worker();
$worker_2->queue($queue);
$pool = new \Jenner\SimpleFork\Pool();
$pool->submit($worker_1);
$pool->submit($worker_2);
$pool->start();
$pool->wait();
示例2: run
{
public function run()
{
for ($i = 0; $i < 10; $i++) {
echo getmypid() . PHP_EOL;
$this->queue()->put(1, $i);
}
}
}
class Worker extends \Jenner\SimpleFork\Process
{
public function run()
{
sleep(5);
for ($i = 0; $i < 10; $i++) {
$res = $this->queue()->get(1);
echo getmypid() . ' = ' . $i . PHP_EOL;
var_dump($res);
}
}
}
$queue = new \Jenner\SimpleFork\Queue\SystemVMessageQueue();
$producer = new Producer();
$producer->queue($queue);
$worker = new Worker();
$worker->queue($queue);
$pool = new \Jenner\SimpleFork\Pool();
$pool->submit($producer);
$pool->submit($worker);
$pool->start();
$pool->wait();