function __construct($host, $port, $timeout = 0) { $this->sw = swoole_server_create($host, $port, self::$sw_mode, SWOOLE_SOCK_TCP); $this->host = $host; $this->port = $port; $this->swooleSetting = array('timeout' => 2.5, 'poll_thread_num' => 2, 'writer_num' => 2, 'worker_num' => 2, 'backlog' => 128, 'open_cpu_affinity' => 1, 'open_tcp_nodelay' => 1); }
function __construct($host, $port, $timeout = 0) { $this->sw = swoole_server_create($host, $port, self::$sw_mode, SWOOLE_SOCK_TCP); $this->host = $host; $this->port = $port; \Swoole\Error::$stop = false; \Swoole_js::$return = true; $this->swooleSetting = array('timeout' => 2.5, 'backlog' => 128, 'log_file' => '/tmp/swoole.log'); }
<?php define('DOCUMENT_ROOT', '/var/www/html/'); /* argv0 server host argv1 server port argv2 server mode SWOOLE_BASE or SWOOLE_THREAD or SWOOLE_PROCESS argv3 sock_type SWOOLE_SOCK_TCP or SWOOLE_SOCK_TCP6 or SWOOLE_SOCK_UDP or SWOOLE_SOCK_UDP6 */ $serv = swoole_server_create("127.0.0.1", 8848, SWOOLE_PROCESS, SWOOLE_SOCK_TCP); swoole_server_setopt($serv, array('worker_num' => 8, 'backlog' => 128, 'max_request' => 20000, 'max_conn' => 50000, 'open_cpu_affinity' => 1, 'open_tcp_nodelay' => 1)); /* argv0 server resource argv1 listen host argv2 listen port argv3 sock_type SWOOLE_SOCK_TCP or SWOOLE_SOCK_TCP6 or SWOOLE_SOCK_UDP or SWOOLE_SOCK_UDP6 */ //swoole_server_addlisten($serv, "127.0.0.1", 9500, SWOOLE_SOCK_UDP); function my_onStart($serv) { echo "Server:start\n"; } function my_onShutdown($serv) { echo "Server:onShutdown\n"; } function my_onTimer($serv, $interval) { echo "Server:Timer Call.Interval={$interval} \n"; } function my_onClose($serv, $fd, $from_id)