A PHP library to create and process background tasks with any queueing service.
Supported queue services:
Features:
- Compatible with any queueing service via provider/publisher interfaces.
- Middleware to hook into the processing flow (inspired by PSR-15).
- Route task messages to workers registered as services in PSR-11/Symfony containers.
Middleware:
- Automatically close timed out Doctrine DBAL connections.
- Automatically clear the Doctrine ORM managers to free memory.
- Limit the maximum execution time of the consumer.
- Limit the maximum number of messages a consumer will process.
- Limit the maximum amount of memory a consumer is allowed to use.
- Retry failed tasks using an exponential backoff strategy.
- Handle signals to terminate the consumer process safely.
PHP 7.0 or above is required.
Install the library with Composer.
composer require keystone/queueCreate a message class for the task.
useKeystone\Queue\Message;
class HardMessage implements Message
{
public$name;
public$count;
publicfunction__construct(string$name, int$count)
{
$this->name = $name;
$this->count = $count;
}
publicfunctiongetKey(): string
{
// The message key is used to determine which queue to publish to.return'hard';
}
}Create a worker class capable of processing the message.
class HardWorker
{
publicfunctionprocess(HardMessage$message)
{
// Do some work to process the message.
}
}Publish a message within your application.
useKeystone\Queue\Publisher;
$publisher = newPublisher(...);
// The message is serialized when publishing and unserialized when consuming$publisher->publish(newHardMessage('Billy', 12));Consume the messages in a long running process.
useKeystone\Queue\Consumer;
useKeystone\Queue\Provider;
$provider = newProvider(...);
$consumer = newConsumer($provider, ...);
// The consumer will poll the queue for new messages and process them.$consumer->consume();- Tom Graham (maintainer)
- Mike Perham for his work on Sidekiq
- Henrik Bjørnskov for his work on Bernard
- Olivier Dolbeau for his work on Swarrot
Released under the MIT Licence. See the bundled LICENSE file for details.
