|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesamqp_pdisconnect.patch (last revision 2012-07-13 12:34 UTC by dyeldandi at gramant dot ru)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-07-18 09:13 UTC] pdezwart@php.net
[2012-07-18 09:13 UTC] pdezwart@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: pdezwart
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 06:00:01 2025 UTC |
Description: ------------ When a connection is created by pconnect, and subsequently broken (server restart) it is not possible to recover that connection. The script would throw AMQPChannelException' with message 'Server connection error: 320, message: CONNECTION_FORCED - broker forced connection closure with reason 'shutdown' and 'AMQPChannelException' with message 'Library error: Broken pipe' from new AMQPChannel($cn) While it is possible to catch it, it's not possible to recover the connection. $cn->isConnected() would still return true, and $cn->disconnect() would do nothing. I wrote a quick patch adding pdisconnect() that deletes the connection from persistent_list zend_hash, marks it not persistent and calls php_amqp_disconnect(). Test script: --------------- Script with disconnect() (which doesn't work) <?php header("Content-type: text/plain"); $cn = new AMQPConnection(); $cn->setHost('localhost'); if(!$cn->pconnect()) { echo "AMQP: Could not create connection.\n"; exit(); } if ($cn->isConnected()) echo "It thinks it's connected\n"; else echo "It thinks it's disconnected\n"; try { $ch = new AMQPChannel($cn); $ex = new AMQPExchange($ch); } catch(AMQPChannelException $e) { echo "Re-creating connection because of $e\n"; $cn->disconnect(); if(!$cn->pconnect()) { echo "AMQP: Could not re-create connection, give up\n"; exit(); } if ($cn->isConnected()) echo "It thinks it's connected\n"; else echo "It thinks it's disconnected\n"; $ch = new AMQPChannel($cn); $ex = new AMQPExchange($ch); } if(!$ex->publish('Hallo!', 'key')) { echo "Error: Message '$text' was not sent.\n"; exit(); } echo "Sent\n"; Script with pdisconnect() (which seems to be working) <?php header("Content-type: text/plain"); $cn = new AMQPConnection(); $cn->setHost('localhost'); if(!$cn->pconnect()) { echo "AMQP: Could not create connection.\n"; exit(); } if ($cn->isConnected()) echo "It thinks it's connected\n"; else echo "It thinks it's disconnected\n"; try { $ch = new AMQPChannel($cn); $ex = new AMQPExchange($ch); } catch(AMQPChannelException $e) { echo "Re-creating connection because of $e\n"; $cn->pdisconnect(); if(!$cn->pconnect()) { echo "AMQP: Could not re-create connection, give up\n"; exit(); } if ($cn->isConnected()) echo "It thinks it's connected\n"; else echo "It thinks it's disconnected\n"; $ch = new AMQPChannel($cn); $ex = new AMQPExchange($ch); } if(!$ex->publish('Hallo!', 'key')) { echo "Error: Message '$text' was not sent.\n"; exit(); } echo "Sent\n"; Expected result: ---------------- It thinks it's connected Sent ... restart rabbitmq server ... It thinks it's connected Re-creating connection because of exception 'AMQPChannelException' with message 'Server connection error: 320, message: CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'' in /var/www/html/test_good.php:12 Stack trace: #0 /var/www/html/test_good.php(12): AMQPChannel->__construct(Object(AMQPConnection)) #1 {main} It thinks it's connected Sent Actual result: -------------- It thinks it's connected Sent ... restart rabbitmq server ... It thinks it's connected Re-creating connection because of exception 'AMQPChannelException' with message 'Server connection error: 320, message: CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'' in /var/www/html/test_bad.php:12 Stack trace: #0 /var/www/html/test_bad.php(12): AMQPChannel->__construct(Object(AMQPConnection)) #1 {main} It thinks it's connected ... in error log: ... [Fri Jul 13 16:25:48 2012] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'AMQPChannelException' with message 'Library error: Broken pipe' in /var/www/html/test_bad.php:23\nStack trace:\n#0 /var/www/html/test_bad.php(23): AMQPChannel->__construct(Object(AMQPConnection))\n#1 {main}\n thrown in /var/www/html/test_bad.php on line 23