Skip to content

Instantly share code, notes, and snippets.

@jctebbal
jctebbal / Resilient_listener
Created September 18, 2014 11:58
Consume RabbitMQ cluster messages behind a load balancer using Pecl AMQP
<?php
/**
when using a RabbitMQ cluster we usually access it via a load balancer (in this case Amazon ELB).
Load balancers allow a maximum idle time to the connections they manage,
this is seen from a client as a connection drop. This script shows how to ignore these drops but
is still able to deal with an actual connectivity problem.
*/
define ( 'MINIMUM_LIFE', 30); //needs to be lower than the load balancer timeout
$last_connection = 0;