/** * Open a new socket based on the instance information * * @param GameQ_Protocols $instance * @param bool $blocking * @throws GameQException * @return boolean|resource */ protected function socket_open(GameQ_Protocols $instance, $blocking = FALSE) { // Create the remote address $remote_addr = sprintf("%s://%s:%d", $instance->transport(), $instance->ip(), $instance->port()); // Create context $context = stream_context_create(array('socket' => array('bindto' => '0:0'))); // Create the socket if (($socket = @stream_socket_client($remote_addr, $errno = NULL, $errstr = NULL, $this->timeout, STREAM_CLIENT_CONNECT, $context)) !== FALSE) { // Set the read timeout on the streams stream_set_timeout($socket, $this->timeout); // Set blocking mode stream_set_blocking($socket, $blocking); } else { // Check to see if we are in debug mode, if so throw the exception if ($this->debug) { throw new GameQException(__METHOD__ . " Error creating socket to server {$remote_addr}. Error: " . $errstr, $errno); } // We didnt create so we need to return false. return FALSE; } unset($context, $remote_addr); // return the socket return $socket; }