videlalvaro/php-amqplib — Issue #8: AMQPSSLConnection overwrites passed $vhost variable
Author: elephantsRule
Created: 2012-02-01 15:12:22+00:00
State: open

It seems to me that the AMQPSSLConnection class overwrites the passed $vhost variable when constructing an object of this class. With the current code, even when I pass a specific VHost (e.g. '/some_host'), php-amqplib will try to connect to the standard '/' VHost. As I don't allow any users (except for admin) to use the standard '/' VHost, the following error is written to the RabbitMQ log:

exception on TCP connection <0.18196.2> from "ip-adress:port"
{channel0_error,opening,
{amqp_error,access_refused,
"access to vhost '/' refused for user 'username'",
'connection.open'}}

The problem lies in code line 15 of the AMQPSSLConnection class:

parent::__construct($host, $port, $user, $password, $vhost="/",
{...}

By replacing $vhost="/" with simply $vhost, the error can be fixed. Code:

parent::__construct($host, $port, $user, $password, $vhost,
{...}

This does not remove default behavior, as $vhost is already defaulted to '/' in the __construct paramters (line 9):

public function __construct($host, $port,
$user, $password,
$vhost="/", $ssl_options = array(), $options = array())
{...}

As mentioned above, this is a problem of SSL connections only.