Skip to content

Commit 05803f2

Browse files
committed
Merge branch '2.0'
2 parents 4e71fb9 + e72cf3a commit 05803f2

File tree

17 files changed

+572
-16
lines changed

17 files changed

+572
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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)

examples/async/dns.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+

examples/async/file.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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');

examples/eventloop/BaseEvent.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+

examples/eventloop/demo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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));

examples/process/multi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
include __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
});

examples/process/single.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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
});

examples/timer/after.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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();

examples/timer/tick.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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();

examples/timer/timer.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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();

0 commit comments

Comments
 (0)