1. Go to this page and download the library: Download tudorr89/phpqdrv 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/ */
tudorr89 / phpqdrv example snippets
use RTIGLOBAL\Phpqdrv\QueueFactory;
use RTIGLOBAL\Phpqdrv\Worker;
$pdo = new PDO('sqlite:' . __DIR__ . '/queue.sqlite');
$queue = QueueFactory::sqlite($pdo);
$queue->push('emails', ['to' => '[email protected]', 'subject' => 'Welcome']);
$worker = new Worker($queue, maxAttempts: 3, sleepSeconds: 1);
$worker->work('emails', function (array $payload): void {
sendEmail($payload['to'], $payload['subject']);
});
use Predis\Client;
use RTIGLOBAL\Phpqdrv\Adapters\PredisAdapter;
use RTIGLOBAL\Phpqdrv\Drivers\RedisQueue;
$queue = new RedisQueue(new PredisAdapter(new Client('redis://127.0.0.1:6379')));
// or: QueueFactory::predis(new Client(...));
// or: QueueFactory::redis($anyRedisClientInterfaceImplementation);
use Pheanstalk\Pheanstalk;
use RTIGLOBAL\Phpqdrv\QueueFactory;
$queue = QueueFactory::pheanstalk(new Pheanstalk('127.0.0.1', 11300));
// or: QueueFactory::beanstalkd($anyBeanstalkdConnectionInterfaceImpl);
interface QueueInterface
{
public function push(string $queue, array $payload, int $delay = 0): JobInterface;
public function pop(string $queue): ?JobInterface;
public function ack(JobInterface $job): void;
public function fail(JobInterface $job): void;
public function release(JobInterface $job, int $delay = 0): void;
public function size(string $queue): int;
public function requeueExpired(): int;
}
$worker = new Worker(
queue: $queue,
maxAttempts: 3, // deliveries before a job is parked as failed
sleepSeconds: 1, // idle polling interval
logger: $psrLogger, // optional PSR-3 logger
);
$worker->work('emails', $processor); // daemon: runs until stopped
$worker->work('emails', $processor, maxJobs: 50); // process 50 jobs, then return
$worker->processNext('emails', $processor); // handle a single job, returns false when empty
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.