Take the 2-minute tour ×

I'm using php-amqp to read and write from a local rabbitmq server. This is for a high traffic website. Following the example at http://code.google.com/p/php-amqp/, I haven't found a way to avoid calling amqp_login with every web request. The call to amqp_login is, by far, the slowest in the sequence. Is there an easy way to bypass the need to call this with every web request? We're using Apache on SuSE linux.

$time = microtime(true);
$connection = amqp_connection_popen('localhost', 5672);
print "connect: ".(microtime(true) - $time) . "\n"; 

$time = microtime(true);
amqp_login($connection, 'guest', 'guest', '/');
print "login: ".(microtime(true) - $time) . "\n"; 

$time = microtime(true);
$channel = 1;
amqp_channel_open($connection, $channel);
print "channel open: ".(microtime(true) - $time) . "\n"; 

$time = microtime(true);
$exchange = 'amq.fanout';
amqp_basic_publish($connection, $channel, $exchange, $routing_key, 'junk', $mandatory = false, $immediate = false, array());
print "publish: ".(microtime(true) - $time) . "\n";

Example Results:

connect: 0.00019311904907227
login: 0.041217088699341
channel open: 0.00034213066101074
publish: 5.6028366088867E-5
share|improve this question
Depending on what you're doing there may be, if you can, try publishing multiple entries at a time. –  xception Oct 11 '12 at 15:53
After discovering this, I am modifying the code so that both queue writes use the same connection + exchange. That way, I can at least avoid logging in twice. –  user1735949 Oct 16 '12 at 15:02

1 Answer 1


Not specifically familiar with this package, however....

It's suprising that it allows persistent connection, but not persistent authentication - one way to fix this would be to key the connection pool based on server+port+username+password rather than just the server+port, which wouldn't require too much change to the code.

If you don't feel like modifying the C code / arguing with the maintainers, then you could run a proxy daemon which maintains an authenticated connection.

share|improve this answer
It is strange (that persistent connection requires re-authenticating). We're not tied to this AMQP package. It's worthwhile to switch to another PHP AMQP package if there is a better one. –  user1735949 Oct 16 '12 at 15:09
I'll keep the proxy server idea in mind. I've already used that in a different case where recreating an object with every web request was too expensive. Things would be so much easier if there were a way to persist a PHP object between requests. –  user1735949 Oct 16 '12 at 15:11
'...persist a PHP object...' there's lots of ways of doing that - the real problem though is that resources can't be serialized. –  symcbean Oct 20 '12 at 22:17

Your Answer


