1. Go to this page and download the library: Download rybakit/phive-task-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/ */
rybakit / phive-task-queue example snippets
// worker.php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Phive\Queue\SysVQueue;
use Phive\TaskQueue\ExecutionContext;
use Phive\TaskQueue\Executor;
use Phive\TaskQueue\ExecutorAdapter\CallableExecutorAdapter;
// create a queue
// see a list of available queues: https://github.com/rybakit/phive-queue#queues
$queue = new SysVQueue(0xDEADBEAF, true);
// create a logger
// can be any PSR-3 compliant logger
$logger = new Logger('worker');
$logger->pushHandler(new StreamHandler(STDOUT, Logger::INFO));
// create a callback
$callback = function ($payload, LoggerInterface $logger) {
$logger->info(strrev($payload));
};
$adapter = new CallbackExecutorAdapter(new DirectCallbackResolver($callback));
$context = new ExecutionContext($queue, $logger);
$executor = new Executor($adapter, $context);
// main loop
while (true) {
if (!$executor->execute()) {
sleep(1);
}
}
// client.php
use Phive\Queue\SysVQueue;
$queue = new SysVQueue(0xDEADBEAF, true);
// send a payload object to the queue and delay execution for 5 seconds
// see supported item types: https://github.com/rybakit/phive-queue#item-types
$queue->push('Hello world!', '+5 seconds');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.