PHP code example of makasim / php-fpm-queue
1. Go to this page and download the library: Download makasim/php-fpm-queue 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/ */
makasim / php-fpm-queue example snippets
# sender.php
use Makasim\PhpFpm\PhpFpmConnectionFactory;
)->createContext();
$queue = $context->createQueue('/app/worker.php');
$message = $context->createMessage('aBody');
$context->createProducer()->send($queue, $message);
# worker.php
use Makasim\PhpFpm\PhpFpmConnectionFactory;
)->createContext();
// or
//$context = (new PhpFpmConnectionFactory('unix:///var/run/php/php7.1-fpm.sock'))->createContext();
$queue = $context->createQueue(__FILE__);
$consumer = $context->createConsumer($queue);
if ($message = $consumer->receiveNoWait()) {
// process message
$consumer->acknowledge($message);
}
bash
php sender.php