小编Mic*_*iel的帖子

AMQPRuntimeException:读取数据时出错.收到0而不是预期的7个字节

它工作,但现在它不再工作了!

我正在使用php-amqplib和RabbitMQ.

当我尝试创建新的AMQP连接时:

$connection = new AMQPConnection('localhost', 5672, 'username', 'password');
Run Code Online (Sandbox Code Playgroud)

导致此错误的库中的代码是:

public function read($n)
{
    $res = '';
    $read = 0;

    while ($read < $n && !feof($this->sock) &&
        (false !== ($buf = fread($this->sock, $n - $read)))) {

        if ($buf === '') {
            continue;
        }

        $read += strlen($buf);
        $res .= $buf;
    }

    if (strlen($res)!=$n) {
        throw new AMQPRuntimeException("Error reading data. Received " .
            strlen($res) . " instead of expected $n bytes");
    }

    return $res;
}
Run Code Online (Sandbox Code Playgroud)

当我把它放在异常之前:

die($res." :".$n);
Run Code Online (Sandbox Code Playgroud)

结果是:

Ï :7 …
Run Code Online (Sandbox Code Playgroud)

php amqp rabbitmq

4
推荐指数
2
解决办法
5649
查看次数

标签 统计

amqp ×1

php ×1

rabbitmq ×1