1. Go to this page and download the library: Download slm/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/ */
slm / queue example snippets
namespace MyModule\Job;
use SlmQueue\Job\AbstractJob;
class EmailJob extends AbstractJob
{
public static function create(string $to, string $subject, string $message): self
{
// This will bypass the constructor, and thus load a job without
// having to load the dependencies.
$job = self::createEmptyJob([
'subject' => $subject,
'to' => $to,
'message' => $message,
]);
// Add some metadata, so we see what is going on.
$job->setMetadata('to', $to);
return $job;
}
private SomeMailService $mailService;
public function __construct(SomeMailService $mailService)
{
$this->mailService = $mailService;
}
public function execute()
{
$payload = $this->getContent();
$to = $payload['to'];
$subject = $payload['subject'];
$message = $payload['message'];
$this->mailService->send($to, $subject, $message);
}
}
namespace MyModule\Controller;
use MyModule\Job\Email as EmailJob;
use SlmQueue\Queue\QueueInterface;
use Laminas\Mvc\Controller\AbstractActionController;
class MyController extends AbstractActionController
{
protected $queue;
public function __construct(QueueInterface $queue)
{
$this->queue = $queue;
}
public function fooAction()
{
// Do some work
$this->queue->push(
EmailJob::create('[email protected]', 'Just hi', 'Hi, I want to say hi!'),
['delay' => 60]
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.