"Socket error: could not connect to host" 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

如果您不能在计算机上ping localhost,则一定没有设置主机文件。在/etc/hosts

中编辑它

最新更新