1. Go to this page and download the library: Download ez-php/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/ */
use EzPhp\Queue\Job;
final class SendWelcomeEmail extends Job
{
protected string $queue = 'emails';
protected int $maxTries = 5;
public function __construct(private readonly string $email) {}
public function handle(): void
{
// send the email ...
}
public function fail(\Throwable $exception): void
{
// log or notify on permanent failure
}
}
use EzPhp\Contracts\QueueInterface;
$queue = $app->make(QueueInterface::class);
$queue->push(new SendWelcomeEmail('[email protected]'));
final class ProcessReport extends Job
{
protected int $delay = 60; // available after 60 seconds
// ...
}
bash
php ez queue:work # process 'default' queue, sleep 3s on empty
php ez queue:work emails # process 'emails' queue
php ez queue:work emails --sleep=5 # custom sleep interval
php ez queue:work --max-jobs=100 # stop after 100 jobs (useful for cron-based workers)
bash
php ez queue:monitor # snapshot of queue depths + failed count
php ez queue:monitor --queues=emails,sms # specific queues
php ez queue:monitor --watch=5 # refresh every 5 seconds
* * * * * php /var/www/html/ez queue:schedule
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.