我正在使用 php-amqp 从本地 rabbitmq 服务器读取和写入。这是一个高流量的网站。按照http://code.google.com/p/php-amqp/的示例,我还没有找到一种方法来避免在每个网络请求中调用 amqp_login。到目前为止,对 amqp_login 的调用是该序列中最慢的。有没有一种简单的方法可以绕过每个 Web 请求都调用它的需要?我们在 SuSE linux 上使用 Apache。
$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";
示例结果:
connect: 0.00019311904907227
login: 0.041217088699341
channel open: 0.00034213066101074
publish: 5.6028366088867E-5