function EpollSocketServer($port) { global $errno, $errstr; if (!extension_loaded('libevent')) { die("Please install libevent extension firstly/n"); } if ($port < 1024) { die("Port must be a number which bigger than 1024/n"); } $socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", $errno, $errstr); if (!$socket_server) { die("{$errstr} ({$errno})"); } stream_set_blocking($socket_server, 0); // 非阻塞 $base = event_base_new(); $event = event_new(); event_set($event, $socket_server, EV_READ | EV_PERSIST, array(__CLASS__, 'ev_accept'), $base); event_base_set($event, $base); event_add($event); event_base_loop($base); self::$connections = array(); self::$buffers = array(); self::$imei = array(); }
public function __construct($port) { global $errno, $errstr; if (!extension_loaded('libevent')) { die("Please install libevent extension firstly\n"); } if ($port < 1024) { die("Port must be a number which bigger than 1024\n"); } $socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", $errno, $errstr); if (!$socket_server) { die("{$errstr} ({$errno})"); } stream_set_blocking($socket_server, 0); // 非阻塞 // event_base_new — Create and initialize new event base $base = event_base_new(); // event_new — Create new event $event = event_new(); // event_set — Prepare an event event_set($event, $socket_server, EV_READ | EV_PERSIST, [__CLASS__, 'ev_accept'], $base); // event_base_set — Associate event base with an event event_base_set($event, $base); // event_add — Add an event to the set of monitored events event_add($event); // event_base_loop — Handle events event_base_loop($base); self::$connections = []; self::$buffers = []; }
function EpollSocketServer($port) { if (!extension_loaded('libevent')) { self::$errstr = "请先安装libevent扩展库。"; return; } if ($port < 1024) { self::$errstr = "端口号不应小于1024"; return; } set_time_limit(0); $socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", self::$errno, self::$errstr); stream_set_blocking($socket_server, 0); // 非阻塞 $base = event_base_new(); $event = event_new(); event_set($event, $socket_server, EV_READ | EV_PERSIST, array(__CLASS__, 'ev_accept'), $base); event_base_set($event, $base); event_add($event); event_base_loop($base); self::$connections = array(); self::$buffers = array(); }