1. Go to this page and download the library: Download codemonster-ru/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/ */
codemonster-ru / queue example snippets
use Codemonster\Queue\Contracts\JobInterface;
use Codemonster\Queue\QueueManager;
final class SendWelcomeEmail implements JobInterface
{
public function handle(): void
{
// Send the email.
}
}
$manager = new QueueManager([
'default' => 'sync',
'connections' => [
'sync' => [
'driver' => 'sync',
],
],
]);
$manager->connection()->push(new SendWelcomeEmail());
use Codemonster\Queue\Contracts\WorkableQueueInterface;
use Codemonster\Queue\Worker;
/** @var WorkableQueueInterface $queue */
$queue = $manager->connection('database');
$queue->push(new SendWelcomeEmail());
(new Worker($queue))->workOnce();
use Codemonster\Queue\Contracts\JobOptionsInterface;
final class SendWelcomeEmail implements JobOptionsInterface
{
public function handle(): void
{
// Send the email.
}
public function maxAttempts(): int
{
return 5;
}
public function backoff(): int|array
{
return [10, 30, 120];
}
public function timeout(): int
{
return 30;
}
}