我有一台CentOS 6
机器,并在其上安装了RabbitMQ 3.7.8
。
然后我写一些示例来发送和接收两条消息。
一切正常,但连接时间正常。从PHP
与AMQP
到RabbitMQ
的连接需要5秒钟以上的时间。
我的样品:
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$a = microtime(true);
$connection = new AMQPStreamConnection('127.0.0.1', 5672, 'guest', 'guest',
'/', false, 'AMQPLAIN', null, 'en_US', 30.0, 20.0, null);
$b = microtime(true);
$channel = $connection->channel();
$c = microtime(true);
$channel->queue_declare('hello', false, false, false, false);
$d = microtime(true);
$msg = new AMQPMessage('Hello World!');
$channel->basic_publish($msg, '', 'hello');
$e = microtime(true);
$msg = new AMQPMessage('Testtt Message!');
$channel->basic_publish($msg, '', 'hello');
$f = microtime(true);
echo " [x] Sent 'Hello World!'\n";
echo '<br/>Connection Time: ' . ($b - $a) . ' Sec.';
echo '<br/>Channel Time: ' . ($c - $b) . ' Sec.';
echo '<br/>Queue Time: ' . ($d - $c) . ' Sec.';
echo '<br/>Publish 1 Time: ' . ($e - $d) . ' Sec.';
echo '<br/>Publish 2 Time: ' . ($f - $e) . ' Sec.';
$channel->close();
$connection->close();
结果:
[x] Sent 'Hello World!'
Connection Time: 5.1319510936737 Sec.
Channel Time: 0.0030379295349121 Sec.
Queue Time: 0.00053691864013672 Sec.
Publish 1 Time: 0.00059103965759277 Sec.
Publish 2 Time: 0.00010395050048828 Sec.
这是怎么了?