1. Go to this page and download the library: Download videlalvaro/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/ */
videlalvaro / php-amqplib example snippets
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$pcntlHandler = function ($signal) {
switch ($signal) {
case \SIGTERM:
case \SIGUSR1:
case \SIGINT:
// some stuff before stop consumer e.g. delete lock etc
pcntl_signal($signal, SIG_DFL); // restore handler
posix_kill(posix_getpid(), $signal); // kill self with signal, see https://www.cons.org/cracauer/sigint.html
case \SIGHUP:
// some stuff to restart consumer
break;
default:
// do nothing
}
};
pcntl_signal(\SIGTERM, $pcntlHandler);
pcntl_signal(\SIGINT, $pcntlHandler);
pcntl_signal(\SIGUSR1, $pcntlHandler);
pcntl_signal(\SIGHUP, $pcntlHandler);
define('AMQP_WITHOUT_SIGNALS', true);
... more code
$sender = new PCNTLHeartbeatSender($connection);
$sender->register();
... code
$sender->unregister();
define('AMQP_DEBUG', true);
... more code
define('AMQP_PROTOCOL', '0.8');
bash
$ composer
bash
$ cd php-amqplib/demo
$ php amqp_consumer.php
bash
$ cd php-amqplib/demo
$ php amqp_publisher.php some text to publish
bash
$ php amqp_publisher.php quit
bash
$ php amqp_consumer_non_blocking.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.