public function connect($socket_path)
{
if (gettype($socket_path) == "string") {
$path_parts = explode(":", $socket_path);
$this->transport = $path_parts[0];
$this->host = substr($path_parts[1], 2, strlen($path_parts[1]));
if (count($path_parts) == 3) {
$this->port = $path_parts[2];
}
JAXLLogger::info("trying " . $socket_path);
if ($this->stream_context) {
$this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout, STREAM_CLIENT_CONNECT, $this->stream_context);
} else {
$this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout);
}
} elseif (is_resource($socket_path)) {
$this->fd =& $socket_path;
} else {
// Some error occurred.
}
if ($this->fd) {
JAXLLogger::debug("connected to " . $socket_path . "");
stream_set_blocking($this->fd, $this->blocking);
// watch descriptor for read/write events
JAXLLoop::watch($this->fd, array('read' => array(&$this, 'on_read_ready')));
return true;
} else {
JAXLLogger::error(sprintf("unable to connect %s with error no: %s, error str: %s", is_null($socket_path) ? 'NULL' : $socket_path, is_null($this->errno) ? 'NULL' : $this->errno, is_null($this->errstr) ? 'NULL' : $this->errstr));
$this->disconnect();
return false;
}
}