fet / queue
Laminas module that integrates with various queue management systems
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- ext-json: *
- laminas/laminas-cli: ^1.13
- laminas/laminas-eventmanager: ^3.15
- laminas/laminas-servicemanager: ^3.24
- laminas/laminas-stdlib: ^3.21
- symfony/console: ^6.4.8 || ^7.4 || ^8.1
Requires (Dev)
- phpunit/phpunit: ^11.5 || ^12.0 || ^13.0
- squizlabs/php_codesniffer: ^3.13 || ^4.0
Suggests
None
Provides
None
Conflicts
- slm/queue: *
Replaces
None
This package is auto-updated.
Last update: 2026-10-27 17:01:29 UTC
README
This is a maintained fork of Webador/SlmQueue (slm/queue), which is no longer
maintained. It is published as fet/queue, starting at version 4.0, and supports the
PHP versions that are currently supported. The SlmQueue\ namespace is
unchanged, so fet/queue cannot be installed next to slm/queue. See UPGRADE.md when coming from
slm/queue 3.x.
SlmQueue is a job queue abstraction layer for Laminas applications, such as Mezzio, that use
laminas-servicemanager, and for Laminas MVC applications (on PHP 8.2
to 8.4). It supports various job queue systems and
makes your application independent from the underlying system you use. Each queue system needs an adapter that
implements SlmQueue\Queue\QueueInterface. Available adapters for fet/queue:
- Doctrine DBAL (
fet/queue-doctrine)
The other adapters written for slm/queue (RabbitMQ,
Amazon SQS) require slm/queue and PHP 8.3 or older, so they cannot be
installed together with fet/queue.
When to use
A job queue helps to offload long or memory-intensive processes from the HTTP requests clients sent to the Laminas application. This will make your response times shorter and your visitors happier. There are many use cases for asynchronous jobs and a few examples are:
- Send an email
- Create a PDF file
- Connect to a third party server over HTTP
In all cases you want to serve the response as soon as possible to your visitor, without letting them wait for this long process. SlmQueue enables you to implement a job queue system very easily within your existing application.
Installation
SlmQueue works with Composer. Make sure you have the composer.phar downloaded and you have a
composer.json file at the root of your project. To install it, add the following line into your composer.json file:
"require": { "fet/queue": "^4.0" }
After installation of the package, you need to complete the following steps to use SlmQueue:
- Register SlmQueue in your application. If you use
laminas-component-installer, this happens automatically.
- Mezzio and other applications using a config provider: add
SlmQueue\ConfigProviderto your configuration (in Mezzio:config/config.php). - Laminas MVC: add
SlmQueueto the modules in yourconfig/modules.config.phporapplication.config.php.
- Mezzio and other applications using a config provider: add
- Copy the
slm_queue.global.php.dist(you can find this file in theconfigfolder of SlmQueue) into yourconfig/autoloadfolder and apply any setting you want.
NB. SlmQueue is a skeleton and therefore useless by itself. You need an adapter for your queue system to push jobs into
the queue, such as fet/queue-doctrine, or your own implementation of
SlmQueue\Queue\QueueInterface (usually extending SlmQueue\Queue\AbstractQueue).
Requirements
- PHP 8.2, 8.3, 8.4 or 8.5
- laminas-servicemanager ^3.24
Laminas MVC applications are supported on PHP 8.2 to 8.4 only, because Laminas MVC is retiring and does not support PHP 8.5. The Laminas MVC integration is deprecated and will be removed in a future major version. See UPGRADE.md.
Code samples
Below are a few snippets which show the power of SlmQueue in your application. The full documentation is available in docs/ directory.
A sample job to send an email with php's mail() might look like this:
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); } }
If you want to inject this job into a queue, you can do this for instance in your request handler:
namespace MyModule\Handler; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use MyModule\Job\EmailJob; use SlmQueue\Queue\QueueInterface; class MyHandler implements RequestHandlerInterface { public function __construct(private QueueInterface $queue) { } public function handle(ServerRequestInterface $request): ResponseInterface { // Do some work $this->queue->push( EmailJob::create('john@doe.com', 'Just hi', 'Hi, I want to say hi!'), ['delay' => 60] ); return new EmptyResponse(); } }
Now the above code lets you insert jobs in a queue, but then you need to spin up a worker which can process these jobs.
SlmQueue integrates with laminas-cli for command line usage. You can start up a worker for queue "default" with the following command:
$ vendor/bin/laminas slm-queue:start default
Contributing
SlmQueue is developed by various fanatic Laminas users. The code is written to be as generic as possible for Laminas applications. If you want to contribute to SlmQueue, fork this repository and start hacking!
Any bugs can be reported as an issue at GitHub. If you want to contribute, please be aware of the following guidelines:
- Fork the project to your own repository
- Use branches to work on your own part
- Create a Pull Request at the canonical SlmQueue repository
- Make sure to cover changes with the right amount of unit tests
- If you add a new feature, please work on some documentation as well
For long-term contributors, push access to this repository is granted.
Who to thank?
Jurian Sluiman and Michaël Gallego did the initial work on creating this repo, and maintained it for a long time.
Currently it is maintained by: