2
我写了一个函数来检查rabbitmq是否在运行。“Socket error:could not connect to host”exception in php-amqp
function getBrokerStatus()
{
log_message("info", "Checking if broker is running....");
try {
$amqpConnection = new AMQPConnection();
$amqpConnection->setLogin("guest");
$amqpConnection->setPassword("guest");
$amqpConnection->setVhost("/");
$amqpConnection->connect();
} catch (Exception $e) {
log_message("info", "Exception: " . $e->getMessage());
return false;
}
if (!$amqpConnection->isConnected()) {
log_message("info", "Cannot connect to the broker! It might not be running");
return false;
}
$amqpConnection->disconnect();
return true;
}
我的代码捕获这个异常。我看到下面的日志 -
Exception: Socket error: could not connect to host.
但我的RabbitMQ服务器在运行,那么为什么我会收到这个异常?我正在使用rabbitmq-server的v3.1.1
。
由于您的代码没有声明代理的主机或状态检查器试图建立连接的主机,所以很难判断。 – marekful
如果有帮助,当我打印'新AMQPConnection()'比如我得到 - 'AMQPConnection对象 ( [登录] => guest虚拟机 [密码] => guest虚拟机 [主持人] =>本地主机 [虚拟主机] =>/ [port] => 5672 [read_timeout] => 0 [write_timeout] => 0 ) ' – Hussain
这很奇怪。显然,连接尝试到同一个主机:端口应该导致相同。我最好的猜测是肯定有一些区别。这并不是什么好说的,但我就是这么想的。找到它。 – marekful