0

このコードにバグがあります (コメントを参照)

<?

$connection = new AMQPConnection(array('host' => 'dev.rabbitmq.com'));
$connection->connect();

for ($i = 0; $i < 3; $i++) {

    // first two times it works.
    // Third - throws: 'AMQPChannelException' with message 'Server connection error: 503, message: COMMAND_INVALID - second 'channel.open' seen
    $channel = new AMQPChannel($connection);

    $queue = new AMQPQueue($channel);
    $queue->setFlags(AMQP_PASSIVE);
    $queue->setName('test' . $i);

    try {
        $queue->declare(); // create queue to get creation errors. This will throw no errors if queue exists
        $queue_exists = true;
    } catch (AMQPQueueException $e) {
        // queue does not exist, so we have error
        $queue_exists = false;
    }
}

誰か助けて?

4

1 に答える 1

0

エラーがスローされた理由を正確に特定できませんでした (AMQP 拡張機能の内部の問題である可能性があります)。私はスクリプトをこのように動作させました。

<?php

$connection = new AMQPConnection(array('host' => 'dev.rabbitmq.com'));
$connection->connect();

$channels = array();
$channels[] = new AMQPChannel($connection);
$channels[] = new AMQPChannel($connection);
$channels[] = new AMQPChannel($connection);

for ($i = 0; $i < 3; $i++) {

    // first two times it works.
    // Third - throws: 'AMQPChannelException' with message 'Server connection error: 503, message: COMMAND_INVALID - second 'channel.open' seen
    $channel = $channels[$i];

    if(isset($queue)){unset($queue);}
        $queue = new AMQPQueue($channel);
        $queue->setFlags(AMQP_PASSIVE);
        $queue->setName('test' . $i);

    try {
        $queue->declare(); // create queue to get creation errors. This will throw no errors    if queue exists
        $queue_exists = true;
    } catch (AMQPQueueException $e) {
        // queue does not exist, so we have error
        $queue_exists = false;
    }
}
于 2012-10-17T16:56:35.110 に答える