swoole创建连接,可自动组包

public function __construct() {

        $this->serv = new \swoole_server("0.0.0.0", 9501,SWOOLE_PROCESS,SWOOLE_SOCK_TCP);

        $this->serv->set(array(

            'open_length_check' => true,

            'package_max_length' => 1024*1024*4,

            'package_length_type' => 'n',

            'package_length_offset' => 21,

            'package_body_offset' => 2,

            'reactor_num' => 2,

            'worker_num' => 8,

            'daemonize' => true,//守护进程是否开启

            'heartbeat_check_interval' => 60,//检查心跳的间隔,心跳超时后会直接断链接

            'heartbeat_idle_time' => 120,

        ));

        $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'));

        $this->serv->start();

    }

你可能感兴趣的:(swoole创建连接,可自动组包)