File tree Expand file tree Collapse file tree 17 files changed +572
-16
lines changed Expand file tree Collapse file tree 17 files changed +572
-16
lines changed Original file line number Diff line number Diff line change 22
33[ ![ Build Status] ( https://travis-ci.org/JanHuang/swoole.svg?branch=master )] ( https://travis-ci.org/JanHuang/swoole )
44[ ![ PHP Require Version] ( https://img.shields.io/badge/php-%3E%3D5.6-8892BF.svg )] ( https://secure.php.net/ )
5- [ ![ Swoole Require Version] ( https://img.shields.io/badge/swoole-%3E%3D2.0.2 -8892BF.svg )] ( http://www.swoole.com/ )
5+ [ ![ Swoole Require Version] ( https://img.shields.io/badge/swoole-%3E%3D1.9.6 -8892BF.svg )] ( http://www.swoole.com/ )
66[ ![ Latest Stable Version] ( https://poser.pugx.org/fastd/swoole/v/stable )] ( https://packagist.org/packages/fastd/swoole )
77[ ![ Total Downloads] ( https://poser.pugx.org/fastd/swoole/downloads )] ( https://packagist.org/packages/fastd/swoole )
88[ ![ Latest Unstable Version] ( https://poser.pugx.org/fastd/swoole/v/unstable )] ( https://packagist.org/packages/fastd/swoole )
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ include __DIR__ . '/../../vendor/autoload.php ' ;
11+
12+ $ dns = new \FastD \Swoole \AsyncIO \DNS ('www.sina.com.cn ' );
13+
14+ $ dns ->lookup (function ($ host , $ ip ) {
15+ echo "{$ host } reslove to {$ ip }\n" ;
16+ });
17+
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ include __DIR__ . '/../../vendor/autoload.php ' ;
11+
12+ $ file = new \FastD \Swoole \AsyncIO \File (__DIR__ . '/async.log ' );
13+
14+ $ file ->write ('hello world ' );
Original file line number Diff line number Diff line change 1+ <?php
2+ use FastD \Swoole \AsyncIO \Event ;
3+
4+ /**
5+ * @author jan huang <bboyjanhuang@gmail.com>
6+ * @copyright 2016
7+ *
8+ * @see https://www.github.com/janhuang
9+ * @see http://www.fast-d.cn/
10+ */
11+ class BaseEvent extends Event
12+ {
13+ public function doRead ($ data )
14+ {
15+ echo $ data ;
16+
17+ if ('exit ' == trim ($ data )) {
18+ $ this ->exit ();
19+ }
20+
21+ return true ;
22+ }
23+ }
24+
25+
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ use FastD \Swoole \EventLoop ;
11+
12+ include __DIR__ . '/../../vendor/autoload.php ' ;
13+ include __DIR__ . '/BaseEvent.php ' ;
14+
15+ $ loop = new EventLoop ();
16+
17+ $ loop ->set (new BaseEvent (STDIN ));
Original file line number Diff line number Diff line change 1111
1212include __DIR__ . '/../../vendor/autoload.php ' ;
1313
14- $ process = new Process ('multi ' , function () {
15- timer_tick (1000 , function ($ id ) {
14+ $ process = new Process ('multi ' , function (swoole_process $ process ) {
15+ timer_tick (1000 , function ($ id ) use ( $ process ) {
1616 static $ index = 0 ;
1717 $ index ++;
1818 echo $ index . PHP_EOL ;
19- if ($ index === 10 ) {
19+ if ($ index === 2 ) {
2020 timer_clear ($ id );
2121 }
2222 });
Original file line number Diff line number Diff line change 1616 static $ index = 0 ;
1717 $ index ++;
1818 echo $ index . PHP_EOL ;
19- if ($ index === 10 ) {
19+ if ($ index === 3 ) {
2020 timer_clear ($ id );
2121 }
2222 });
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ $ timer = include __DIR__ . '/timer.php ' ;
11+
12+ $ timer ->after ();
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ $ timer = include __DIR__ . '/timer.php ' ;
11+
12+ $ timer ->tick ();
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @author jan huang <bboyjanhuang@gmail.com>
4+ * @copyright 2016
5+ *
6+ * @see https://www.github.com/janhuang
7+ * @see http://www.fast-d.cn/
8+ */
9+
10+ include __DIR__ . '/../../vendor/autoload.php ' ;
11+
12+ class DemoTimer extends \FastD \Swoole \Timer
13+ {
14+ protected $ count = 0 ;
15+
16+ /**
17+ * @param $id
18+ * @param array $params
19+ * @return mixed
20+ */
21+ public function doTick ($ id , array $ params = [])
22+ {
23+ echo ++$ this ->count ;
24+ if (3 === $ this ->count ) {
25+ $ this ->clear ();
26+ }
27+ }
28+ }
29+
30+ return new DemoTimer ();
You can’t perform that action at this time.
0 commit comments