public function __construct($host, $port, $user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = NULL, $locale = "en_US", $connection_timeout = 3, $read_write_timeout = 3, $context = null) { if ($user && $password) { $login_response = new AMQPWriter(); $login_response->write_table(array("LOGIN" => array('S', $user), "PASSWORD" => array('S', $password))); $login_response = substr($login_response->getvalue(), 4); //Skip the length } else { $login_response = NULL; } $d = self::$LIBRARY_PROPERTIES; while (true) { $this->channels = array(); // The connection object itself is treated as channel 0 parent::__construct($this, 0); $this->channel_max = 65535; $this->frame_max = 131072; $errstr = $errno = NULL; $this->sock = NULL; //TODO clean up if ($context) { $remote = sprintf('ssl://%s:%s', $host, $port); $this->sock = stream_socket_client($remote, $errno, $errstr, $connection_timeout, STREAM_CLIENT_CONNECT, $context); } else { $remote = sprintf('tcp://%s:%s', $host, $port); $this->sock = stream_socket_client($remote, $errno, $errstr, $connection_timeout, STREAM_CLIENT_CONNECT); } if (!$this->sock) { throw new Exception("Error Connecting to server({$errno}): {$errstr} "); } stream_set_timeout($this->sock, $read_write_timeout); stream_set_blocking($this->sock, 1); $this->input = new AMQPReader(null, $this->sock); $this->write(self::$AMQP_PROTOCOL_HEADER); $this->wait(array("10,10")); $this->x_start_ok($d, $login_method, $login_response, $locale); $this->wait_tune_ok = true; while ($this->wait_tune_ok) { $this->wait(array("10,20", "10,30")); } $host = $this->x_open($vhost, "", $insist); if (!$host) { return; } // we weren't redirected // we were redirected, close the socket, loop and try again if ($this->debug) { MiscHelper::debug_msg("closing socket"); } @fclose($this->sock); $this->sock = NULL; } }
public function __construct($connection, $channel_id = NULL, $auto_decode = true) { $this->frameBuilder = new FrameBuilder(); if ($channel_id == NULL) { $channel_id = $connection->get_free_channel_id(); } parent::__construct($connection, $channel_id); if ($this->debug) { MiscHelper::debug_msg("using channel_id: " . $channel_id); } $this->default_ticket = 0; $this->is_open = false; $this->active = true; // Flow control $this->alerts = array(); $this->callbacks = array(); $this->auto_decode = $auto_decode; $this->x_open(); }