'30070', 'address' => '127.0.0.1'); private $_sock; private $_port; private $_address; /** * 锁定 * * @return integer|false 成功返回绑定端口号 */ public function lock() { $this->_port = (int) $this->_specificOptions['port']; $this->_address = $this->_specificOptions['address']; if (($this->_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { return false; } if (@socket_bind($this->_sock, $this->_address, $this->_port) === false) { return false; } if (@socket_listen($this->_sock, 5) === false) { return false; } return $this->_port; } /** * Release locker */ public function unlock() { if ($this->_sock !== false) @socket_close($this->_sock); } } // End ^ Native EOL ^ encoding