server:
<?php
//tcp服务器
class Server
{
private $serv;
public function __construct()
{
$this->serv = new Swoole\Server('0.0.0.0', 1216);
$this->serv->set([
'worker_num' => 10,
'deamonize' => true,
]);
//增加新的监控的ip:post:mode
$this->serv->addlistener("0.0.0.0", 2345, SWOOLE_SOCK_TCP);
$this->serv->on('Start', array($this, 'onStart'));
$this->serv->on('Connect', array($this, 'onConnect'));
$this->serv->on('Receive', array($this, 'onReceive'));
$this->serv->on('Close', array($this, 'onClose'));
//master进程启动后, fork出Manager进程, 然后触发ManagerStart
$this->serv->on('ManagerStart', function (\swoole_server $server) {
echo "On manager start.";
});