note 105947 added to class.amqpqueue
| From: | bolo at nospam dot autistici dot org | Date: | Tue, 27 Sep 2011 11:03:04 +0000 |
| Subject: | note 105947 added to class.amqpqueue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183472@lists.php.net to get a copy of this message | ||
Function that perform a php publisher daemon.
<?php
//First initialise the connection to Rabbit server
function amqp_connection() {
$connection = new AMQPConnection();
$connection->setLogin('guest');
$connection->setPassword('guest');
$connection->connect();
if (!$connection->isConnected()) {
echo "Cannot connect to the broker";
}
return $connection;
}
//This is the daemon, it should be more performant because the sleep(1) run the publisher every 1
second. Rabbit is more faster.
function receiver($exchange, $rk, $queuename) {
$connection=amqp_connection();
$queue = new AMQPQueue($connection);
$queue->declare($queuename);
$queue->bind($exchange, $rk);
while(true){
$msg=$queue->get();
if ($msg['count']>-1){
echo "\n--------\n";
print_r($msg['msg']);
echo "\n--------\n";
}
sleep(1);
}
if (!$connection->disconnect()) {
throw new Exception('Could not disconnect');
}
}
?>
P.S. run the daemon with ~$ php /pathto/php.ini functioncaller.php
----
Server IP: 69.147.83.197
Probable Submitter: 155.185.212.161
----
Manual Page -- http://www.php.net/manual/en/class.amqpqueue.php
Edit -- https://master.php.net/note/edit/105947
Del: integrated -- https://master.php.net/note/delete/105947/integrated
Del: useless -- https://master.php.net/note/delete/105947/useless
Del: bad code -- https://master.php.net/note/delete/105947/bad+code
Del: spam -- https://master.php.net/note/delete/105947/spam
Del: non-english -- https://master.php.net/note/delete/105947/non-english
Del: in docs -- https://master.php.net/note/delete/105947/in+docs
Del: other reasons-- https://master.php.net/note/delete/105947
Reject -- https://master.php.net/note/reject/105947
Search -- https://master.php.net/manage/user-notes.php