forked from walkor/web-msg-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
443 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker; | ||
|
||
use Workerman\Connection\TcpConnection; | ||
|
||
use \Workerman\Worker; | ||
use \Workerman\Connection\AsyncTcpConnection; | ||
use \Workerman\Protocols\GatewayProtocol; | ||
|
@@ -185,6 +199,10 @@ public function checkGatewayConnections() | |
$gateway_connection->onMessage = array($this, 'onGatewayMessage'); | ||
$gateway_connection->onClose = array($this, 'onClose'); | ||
$gateway_connection->onError = array($this, 'onError'); | ||
if(TcpConnection::$defaultMaxSendBufferSize == $gateway_connection->maxSendBufferSize) | ||
{ | ||
$gateway_connection->maxSendBufferSize = 10*1024*1024; | ||
} | ||
$gateway_connection->connect(); | ||
$this->_connectingGatewayAddress[$addr] = 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker; | ||
|
||
use Workerman\Connection\TcpConnection; | ||
|
||
use \Workerman\Worker; | ||
use \Workerman\Lib\Timer; | ||
use \Workerman\Protocols\GatewayProtocol; | ||
|
@@ -171,7 +185,7 @@ public function run() | |
*/ | ||
public function onClientMessage($connection, $data) | ||
{ | ||
$connection->pingNotResponseCount = 0; | ||
$connection->pingNotResponseCount = -1; | ||
$this->sendToWorker(GatewayProtocol::CMD_ON_MESSAGE, $connection, $data); | ||
} | ||
|
||
|
@@ -195,7 +209,7 @@ public function onClientConnect($connection) | |
// 连接的session | ||
$connection->session = ''; | ||
// 该连接的心跳参数 | ||
$connection->pingNotResponseCount = 0; | ||
$connection->pingNotResponseCount = -1; | ||
// 保存客户端连接connection对象 | ||
$this->_clientConnections[$connection->globalClientId] = $connection; | ||
// 保存该连接的内部gateway通讯地址 | ||
|
@@ -353,7 +367,7 @@ protected function createGlobalClientId() | |
public function onWorkerStart() | ||
{ | ||
// 分配一个内部通讯端口 | ||
$this->lanPort = $this->startPort - posix_getppid() + posix_getpid(); | ||
$this->lanPort = function_exists('posix_getppid') ? $this->startPort - posix_getppid() + posix_getpid() : $this->startPort; | ||
if($this->lanPort<0 || $this->lanPort >=65535) | ||
{ | ||
$this->lanPort = rand($this->startPort, 65535); | ||
|
@@ -403,6 +417,10 @@ public function onWorkerStart() | |
public function onWorkerConnect($connection) | ||
{ | ||
$connection->remoteAddress = $connection->getRemoteIp().':'.$connection->getRemotePort(); | ||
if(TcpConnection::$defaultMaxSendBufferSize == $connection->maxSendBufferSize) | ||
{ | ||
$connection->maxSendBufferSize = 10*1024*1024; | ||
} | ||
$this->_workerConnections[$connection->remoteAddress] = $connection; | ||
} | ||
|
||
|
@@ -518,7 +536,7 @@ protected function registerAddress() | |
Lock::release(); | ||
if(get_class($store) == 'Memcached') | ||
{ | ||
$msg = " registerAddress fail : " . $store->getResultMessage(); | ||
$msg = " registerAddress fail : Memcache Error " . $store->getResultMessage(); | ||
} | ||
$this->log($msg); | ||
return false; | ||
|
@@ -583,10 +601,13 @@ public function ping() | |
$connection->destroy(); | ||
continue; | ||
} | ||
$connection->pingNotResponseCount++; | ||
if($this->pingData) | ||
// $connection->pingNotResponseCount为-1说明最近客户端有发来消息,则不给客户端发送心跳 | ||
if($connection->pingNotResponseCount++ >= 0) | ||
{ | ||
$connection->send($this->pingData); | ||
if($this->pingData) | ||
{ | ||
$connection->send($this->pingData); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib; | ||
|
||
/** | ||
* 上下文 包含当前用户uid, 内部通信local_ip local_port socket_id ,以及客户端client_ip client_port | ||
* @author walkor | ||
*/ | ||
class Context | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib; | ||
|
||
/** | ||
* 数据库类 | ||
* @author walkor <[email protected]> | ||
*/ | ||
class Db | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib; | ||
|
||
/** | ||
* | ||
* 数据发送相关 | ||
* @author walkor <[email protected]> | ||
* | ||
*/ | ||
use \Workerman\Protocols\GatewayProtocol; | ||
use \GatewayWorker\Lib\Store; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib; | ||
/** | ||
* 锁 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib; | ||
|
||
/** | ||
* 存储类 | ||
* 这里用memcache实现 | ||
* @author walkor <[email protected]> | ||
*/ | ||
class Store | ||
{ | ||
|
@@ -52,6 +64,26 @@ public static function instance($config_name) | |
} | ||
return self::$instance[$config_name]; | ||
} | ||
// redis 驱动 | ||
elseif(\Config\Store::$driver == \Config\Store::DRIVER_REDIS) | ||
{ | ||
if(!isset(\Config\Store::$$config_name)) | ||
{ | ||
echo "\\Config\\Store::$config_name not set\n"; | ||
throw new \Exception("\\Config\\Store::$config_name not set\n"); | ||
} | ||
if(!isset(self::$instance[$config_name])) | ||
{ | ||
self::$instance[$config_name] = new \GatewayWorker\Lib\StoreDriver\Redis(); | ||
// 只选择第一个ip作为服务端 | ||
$address = current(\Config\Store::$$config_name); | ||
list($ip, $port) = explode(':', $address); | ||
$timeout = 1; | ||
self::$instance[$config_name]->connect($ip, $port, $timeout); | ||
self::$instance[$config_name]->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_IGBINARY); | ||
} | ||
return self::$instance[$config_name]; | ||
} | ||
// 文件驱动 | ||
else | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib\StoreDriver; | ||
|
||
/** | ||
* | ||
* 这里用php数组文件来存储数据, | ||
* 为了获取高性能需要用类似memcache的存储 | ||
* @author walkor <[email protected]> | ||
* | ||
*/ | ||
|
||
class File | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace GatewayWorker\Lib\StoreDriver; | ||
|
||
/** | ||
* Redis | ||
*/ | ||
|
||
class Redis extends \Redis | ||
{ | ||
public function increment($key) | ||
{ | ||
return parent::incr($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Workerman; | ||
|
||
// 定义Workerman根目录 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Workerman\Connection; | ||
|
||
use Workerman\Events\Libevent; | ||
|
@@ -9,7 +21,6 @@ | |
|
||
/** | ||
* 异步tcp连接类 | ||
* @author walkor<[email protected]> | ||
*/ | ||
class AsyncTcpConnection extends TcpConnection | ||
{ | ||
|
@@ -52,6 +63,7 @@ public function __construct($remote_address) | |
$this->id = self::$_idRecorder++; | ||
// 统计数据 | ||
self::$statistics['connection_count']++; | ||
$this->maxSendBufferSize = self::$defaultMaxSendBufferSize; | ||
} | ||
|
||
public function connect() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
<?php | ||
/** | ||
* This file is part of workerman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<[email protected]> | ||
* @copyright walkor<[email protected]> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Workerman\Connection; | ||
|
||
use Workerman\Events\Libevent; | ||
use Workerman\Events\Select; | ||
use Workerman\Events\EventInterface; | ||
|
@@ -8,7 +21,6 @@ | |
|
||
/** | ||
* connection类的接口 | ||
* @author walkor<[email protected]> | ||
*/ | ||
abstract class ConnectionInterface | ||
{ | ||
|
Oops, something went wrong.