PHP code example of romainrg / codeigniter-php-amqplib
1. Go to this page and download the library: Download romainrg/codeigniter-php-amqplib library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
romainrg / codeigniter-php-amqplib example snippets
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$msg = new AMQPMessage($msg_body);
$ch->batch_basic_publish($msg, $exchange);
$msg2 = new AMQPMessage($msg_body);
$ch->batch_basic_publish($msg2, $exchange);
$pcntlHandler = function ($signal) {
switch ($signal) {
case \SIGTERM:
case \SIGUSR1:
case \SIGINT:
// some stuff before stop consumer e.g. delete lock etc
exit(0);
break;
case \SIGHUP:
// some stuff to restart consumer
break;
default:
// do nothing
}
};
declare(ticks = 1) {
pcntl_signal(\SIGTERM, $pcntlHandler);
pcntl_signal(\SIGINT, $pcntlHandler);
pcntl_signal(\SIGUSR1, $pcntlHandler);
pcntl_signal(\SIGHUP, $pcntlHandler);
}
define('AMQP_WITHOUT_SIGNALS', true);
... more code
define('AMQP_DEBUG', true);
... more code
define('AMQP_PROTOCOL', '0.8');
javascript
{
"varo/php-amqplib": "2.5.*"
}
}
bash
$ cd php-amqplib/demo
$ php amqp_consumer.php
bash
$ cd php-amqplib/demo
$ php amqp_publisher.php some text to publish