Skip to content

Commit a975fd7

Browse files
committed
update process handle method, update docs
1 parent 5c9f2d9 commit a975fd7

File tree

6 files changed

+55
-36
lines changed

6 files changed

+55
-36
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# FastD Swoole
22

33
[![Build Status](https://travis-ci.org/JanHuang/swoole.svg?branch=master)](https://travis-ci.org/JanHuang/swoole)
4-
[![Latest Stable Version](https://poser.pugx.org/fastd/swoole/v/stable)](https://packagist.org/packages/fastd/swoole)
4+
[![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%3D1.8-8892BF.svg)](http://www.swoole.com/)
6+
[![Latest Stable Version](https://poser.pugx.org/fastd/swoole/v/stable)](https://packagist.org/packages/fastd/swoole)
57
[![Total Downloads](https://poser.pugx.org/fastd/swoole/downloads)](https://packagist.org/packages/fastd/swoole)
68
[![Latest Unstable Version](https://poser.pugx.org/fastd/swoole/v/unstable)](https://packagist.org/packages/fastd/swoole)
79
[![License](https://poser.pugx.org/fastd/swoole/license)](https://packagist.org/packages/fastd/swoole)

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"minimum-stability": "dev",
1313
"require": {
1414
"php": ">=5.6",
15-
"ext-swoole": ">=1.8",
1615
"fastd/packet": "~1.3.0",
1716
"fastd/http": "~3.0.0",
1817
"symfony/console": "~3.2.0"

examples/multi_port_server.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ public function doWork(swoole_server $server, $fd, $data, $from_id)
2222
{
2323
return 'hello server1';
2424
}
25-
26-
/**
27-
* Please return swoole configuration array.
28-
*
29-
* @return array
30-
*/
31-
public function configure()
32-
{
33-
// TODO: Implement configure() method.
34-
}
3525
}
3626

3727
class Server2 extends \FastD\Swoole\Server\Tcp
@@ -47,16 +37,6 @@ public function doWork(swoole_server $server, $fd, $data, $from_id)
4737
{
4838
return 'hello server2';
4939
}
50-
51-
/**
52-
* Please return swoole configuration array.
53-
*
54-
* @return array
55-
*/
56-
public function configure()
57-
{
58-
// TODO: Implement configure() method.
59-
}
6040
}
6141

6242
$server = new Server('tcp server', 'tcp://127.0.0.1:9527');

examples/process/handle.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
use FastD\Swoole\Process;
11+
12+
include __DIR__ . '/../../vendor/autoload.php';
13+
14+
class DemoProcess extends Process
15+
{
16+
/**
17+
* Process handle
18+
*
19+
* @return callable
20+
*/
21+
public function handle(swoole_process $swoole_process)
22+
{
23+
timer_tick(1000, function ($id) {
24+
static $index = 0;
25+
$index++;
26+
echo $index . PHP_EOL;
27+
if ($index === 10) {
28+
timer_clear($id);
29+
}
30+
});
31+
}
32+
}
33+
34+
$process = new DemoProcess();
35+
36+
$process->start();
37+
38+
$process->wait(function ($ret) {
39+
echo 'PID: ' . $ret['pid'];
40+
});

examples/watch.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ public function doWork(swoole_server $server, $fd, $data, $from_id)
2222
{
2323
return 'hello tcp';
2424
}
25-
26-
/**
27-
* Please return swoole configuration array.
28-
*
29-
* @return array
30-
*/
31-
public function configure()
32-
{
33-
// TODO: Implement configure() method.
34-
}
3525
}
3626

3727
$server = new DemoServer('watch server', 'tcp://0.0.0.0:9527');

src/Process.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ class Process
6262
* @param bool $stdout
6363
* @param bool $pipe
6464
*/
65-
public function __construct($name, callable $callback, $stdout = false, $pipe = true)
65+
public function __construct($name = null, callable $callback = null, $stdout = false, $pipe = true)
6666
{
67-
$this->name($name);
67+
$this->name = $name;
6868

6969
$this->stdout = $stdout;
7070

7171
$this->pipe = $pipe;
7272

73-
$this->callback = $callback;
73+
$this->callback = null === $callback ? [$this, 'handle'] : $callback;
7474

75-
$this->process = new swoole_process($callback, $stdout, $pipe);
75+
$this->process = new swoole_process($this->callback, $stdout, $pipe);
7676
}
7777

7878
/**
@@ -209,4 +209,12 @@ public function getProcess()
209209
{
210210
return $this->process;
211211
}
212+
213+
/**
214+
* Process handle
215+
*
216+
* @param $swoole_process
217+
* @return callable
218+
*/
219+
public function handle(swoole_process $swoole_process){}
212220
}

0 commit comments

Comments
 (0)