[rabbitmq-discuss] Persistent connections with Amqphp

Robin Harvey harvey.robin at gmail.com
Wed Jul 6 19:24:15 BST 2011


Hi,

A couple of people recently asked about support for persistent connections,
after a bit of hacking around I've uploaded an update which has basic
persistent connection support:
https://github.com/BraveSirRobin/amqphp(check the 0.9.1 tag)


The implementation turned out to be fairly straightforward, I only had to
add the STREAM_CLIENT_PERSIST flag to the existing stream_socket_client()
call, so the changes weren't too invasive.  I've created a new "Connection"
object called PConnection, and set up a simple framework to persist amqp
connection parameters between web requests.  The amqp connection setup
process is only run the first time the PConnection is opened, so both the
Amqp "session" and TCP connection remain after the web request and are
re-used by subsequent requests to that process.  My plan is to add support
for persisting Channels as well, possibly by having API calls use
channel.flow to inform the broker during the web request wakeup / sleep
routines.

I'd be interested to hear what the RabbitMQ people think about the likely
behavior of PHP "persistent connections", which may include:

 * If the web server is restarted, all open client connections are dropped
without going through the amqp shutdown sequence, so you get lots of "closed
abruptly" errors in the log.
 * If a web server has no web requests to process then the persistent client
can't respond to any messages the broker sends; the client will "go quiet".

In case you don't know what PHP persistent connections are, they're
basically a socket re-use method for web servers, the idea is that the
socket remains open between web requests in order to avoid TCP setup /
teardown overheads on busy sites.

If you'd like to test this then check out the demo-multi-producer.php
script, I've run this inside a PHP-FPM / Nginx setup and it seems to work
fine.

Thanks,
--Robin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20110706/2bd318c5/attachment.htm>


More information about the rabbitmq-discuss mailing list