Skip to content
This repository was archived by the owner on Oct 24, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions bin/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,21 @@ function StartServSock($RunServer)
));
$serv->on('WorkerStart', function ($serv, $workerId) {
//监控周期
$serv->addtimer(1000);

//edit by Terry Gao at 2016-12-27
//由于新版Swoole(1.8+)移除了addtimer方法,改用swoole_server->tick方法替代
//相应的onTimer回调也改为onTickTimer
//$serv->addtimer(1000);
$timeer_id = $serv->tick(1000, function($timer_id, $serv){
onTickTimer($serv);
}, $serv);
});
//定时器中操作 主要为轮巡 启动服务
$serv->on('Timer', function ($serv, $interval) {
StartLogTimer(__LINE__ . 'timer start ' . time());
// $serv->on('Timer', function ($serv, $interval) {
function onTickTimer($serv)
{
StartLogTimer(__LINE__ . ' timer start ' . time());
if (empty($serv->runServer)) {
StartLogTimer(__LINE__ . ' ' . 'no server is running ' . PHP_EOL);
StartLogTimer(__LINE__ . ' no server is running ' . PHP_EOL);
return;
};
foreach ($serv->runServer as $serverName) {
Expand All @@ -212,14 +219,14 @@ function StartServSock($RunServer)
if (empty($ret)) {//挂了 什么都没有 之后可能要通过数量来获取
//todo
StartServ($serverName['php'], 'start', $serverName['name']);
StartLogTimer(__LINE__ . date('Y-m-d H:i:s') . ' ' . print_r($serverName, true) . ' server is dead , start to restart' . PHP_EOL);
StartLogTimer(__LINE__ .' '. date('Y-m-d H:i:s') . ' ' . print_r($serverName, true) . ' server is dead , start to restart' . PHP_EOL);

} else {
StartLogTimer(__LINE__ . date('Y-m-d H:i:s') . ' ' . print_r($serverName, true) . ' server is running success' . PHP_EOL);
StartLogTimer(__LINE__ .' '. date('Y-m-d H:i:s') . ' ' . print_r($serverName, true) . ' server is running success' . PHP_EOL);
}
}
});

// });
}
$serv->on('connect', function ($serv, $fd, $from_id) {
echo "[#" . posix_getpid() . "]\tClient@[$fd:$from_id]: Connect.\n";
});
Expand Down
2 changes: 1 addition & 1 deletion conf/testHttpServ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ php = '/usr/local/php/bin/php'
; worker num
worker_num = 16
; task num
task_worker_num = 0
task_worker_num = 8
dispatch_mode = 2
daemonize = 1

Expand Down
10 changes: 8 additions & 2 deletions lib/Swoole/Network/Protocol/PullServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function onFinish($serv, $taskId, $data)
}

//启动定时期,监听IPC通道
public function onTimer($serv, $interval)
public function onTimer($timer_id, $interval)
{
$res = $this->timeJobs[$interval];
if ($data = $res->recv()) {
Expand Down Expand Up @@ -102,7 +102,13 @@ private function timePoll($serv)
{
if (is_array($this->timeJobs)) {
foreach ($this->timeJobs as $k => $v) {
$serv->addtimer($k);
//edit by Terry Gao at 2016-12-27
//由于新版Swoole(1.8+)移除了addtimer方法,改用swoole_server->tick方法替代
//相应的onTimer回调也稍作调整
//$serv->addtimer($k);
$serv->tick($k, function ($timer_id, $params){
$this->onTimer($timer_id, $params);
}, $k);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Swoole/Network/SimpleServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* To change this template use File | Settings | File Templates.
* 对应swoole的base模式的server
*/
class SimpleServer extends Swoole\Server implements Swoole\Server\Driver
class SimpleServer extends Swoole\Servers implements Swoole\Server\Driver
{
protected $mode = SWOOLE_BASE;

Expand Down
2 changes: 1 addition & 1 deletion lib/Swoole/Network/TcpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Class Server
* @package Swoole\Network
*/
class TcpServer extends \Swoole\Server implements \Swoole\Server\Driver
class TcpServer extends \Swoole\Servers implements \Swoole\Server\Driver
{
protected $sockType = SWOOLE_SOCK_TCP;

Expand Down
2 changes: 1 addition & 1 deletion lib/Swoole/Network/UdpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Class Server
* @package Swoole\Network
*/
class UdpServer extends \Swoole\Server
class UdpServer extends \Swoole\Servers
{
protected $sockType = SWOOLE_SOCK_UDP;

Expand Down
14 changes: 12 additions & 2 deletions lib/Swoole/Server.php → lib/Swoole/Servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

namespace Swoole;

abstract class Server implements Server\Driver
/**
* Class Servers
* @editor Terry Gao
* @date 2016-12-27
* 因命名空间类名与文件夹重名,Server类改为Severs
*
* @package Swoole
*/
abstract class Servers implements Server\Driver
{
protected $sw;
protected $processName = 'swooleServ';
Expand Down Expand Up @@ -128,7 +136,9 @@ private function initServer()
$this->sw->on('Receive', array($this, 'onReceive'));
$this->sw->on('Close', array($this, 'onClose'));
$this->sw->on('WorkerStop', array($this, 'onWorkerStop'));
$this->sw->on('timer', array($this, 'onTimer'));
//edit by Terry Gao at 2016-12-27
//onTimer事件是由已移除的addTimer方法添加的定时器回调的,新版的Swoole已经没有该事件
//$this->sw->on('timer', array($this, 'onTimer'));
if ($this->enableHttp) {
$this->sw->on('Request', array($this, 'onRequest'));
}
Expand Down
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Tencent Server Framework
=======================
========================

## 2016-12-27 更新内容

- 适配最新的swoole(pecl安装,目前最新版为1.9.2),用swoole_server->tick替代swoole_server->addTimer
- 修正命名空间重名问题(Server类与Server目录重名)
- 运行前需要修改conf/testHttpServ.ini中的root和php两个路径,可将路径root指向examples/src目录下的index.php,root为php的安装路径
- 运行需要使用root用户,请先sudo su,直接使用sudo php bin/swoole.php testHttpServ.ini会报错

## 通知

Expand Down