Skip to content

Commit 22691ee

Browse files
committed
add queue demo
1 parent f78ae36 commit 22691ee

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/queue.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @author jan huang <bboyjanhuang@gmail.com>
4+
* @copyright 2016
5+
*
6+
* @link https://www.github.com/janhuang
7+
* @link http://www.fast-d.cn/
8+
*/
9+
10+
include __DIR__ . '/../vendor/autoload.php';
11+
12+
$queue = new \FastD\Swoole\Queue(function ($worker) {
13+
while (true) {
14+
$recv = $worker->pop();
15+
echo "From Master: $recv\n";
16+
}
17+
});
18+
19+
$queue->start();
20+
21+
while (true) {
22+
$queue->push('hello');
23+
sleep(1);
24+
}
25+
26+
27+
$queue->wait(function ($ret) {
28+
echo 'PID: ' . $ret['pid'];
29+
});

0 commit comments

Comments
 (0)