2012-10-17 15 views
0

我的錯誤與此代碼(見註釋)php amqp通道創建的bug?

<? 

$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; 
    } 
} 

任何人幫助嗎?

+0

您可以幫助我們測試解決此問題的https://github.com/pdezwart/php-amqp/pull/57。 –

回答

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; 
    } 
}