Download the PHP package vaibhavpandeyvpz/qatar without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/qatar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/qatar
More information about vaibhavpandeyvpz/qatar
Files in vaibhavpandeyvpz/qatar
Package qatar
Short Description Framework agnostic PHP library for publishing and consuming jobs using Redis and ElasticMQ backends.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/qatar
Informations about the package qatar
Qatar (कतार)
Framework agnostic PHP library for publishing and consuming jobs using Redis and ElasticMQ/SQS backends.
Qatar:
कतार(Queue)
Features
- 🚀 Fast: Efficient job processing with Redis or ElasticMQ/SQS backends
- 🔄 Reliable: Automatic retries with configurable delays
- ⏰ Delayed Jobs: Schedule jobs to run in the future
- 👷 Multiple Workers: Run multiple workers concurrently
- 🎯 Simple API: Clean, intuitive interface for job management
- 🔧 Flexible: Framework agnostic - use with any PHP application
- 📝 Type-safe: Full PHP 8.2+ type hints and modern language features
- ⚡ Graceful Shutdown: Workers handle termination signals properly
- 💾 Two Backends: Choose between Redis (fast) or ElasticMQ/SQS (distributed).
- Note: Backend-specific drivers (
predisoraws-sdk-php) are suggested and must be installed separately.
- Note: Backend-specific drivers (
Requirements
- PHP 8.2 or higher
- Redis server + PhpRedis OR
predis/predis(forRedisQueue) - ElasticMQ or AWS SQS +
aws/aws-sdk-php(forElasticMQQueue) - JSON extension (
ext-json) for payload serialization (usually enabled by default)
Installation
Install via Composer:
Local Development Setup
For local testing, use Docker Compose to run Redis and ElasticMQ:
This will start:
- Redis on
localhost:6379 - ElasticMQ on
localhost:9324(SQS-compatible API) - ElasticMQ UI on
localhost:9325(monitoring)
Quick Start
Creating a Job
Implementing Qatar\Job is simple:
By extending Job, you get default implementations for:
retries(): Returns3delay(): Returns60secondsfailed(): Empty handler
Override them as needed:
Publishing Jobs
Running Workers
API Reference
Qatar\Queue Interface
| Method | Description |
|---|---|
push(string $job, array $payload, ?int $delay = null): string |
Add a job to the queue. Returns job ID. |
pop(?int $timeout = null): ?JobPayload |
Retrieve next job. Optionally wait for $timeout seconds. |
ack(string $id): bool |
Acknowledge successful completion of a job. |
nack(string $id, ?int $delay = null): bool |
Record a failure and schedule a retry. |
size(): int |
Get total number of pending and delayed jobs. |
purge(): void |
Clear all jobs from the queue. |
Qatar\Worker Class
The worker executes jobs from a queue. It is not final, so you can extend it to override resolveJob() for dependency injection.
WorkerOptions
| Option | Default | Description |
|---|---|---|
sleep |
3 |
Seconds to wait when the queue is empty. |
maxJobs |
null |
Max number of jobs to process before stopping. |
maxTime |
null |
Max seconds to run before stopping. |
memory |
128 |
Memory limit in MB. Worker stops if exceeded. |
stopOnEmpty |
false |
If true, worker quits when queue is empty. |
Advanced Usage
Exponential Backoff
Implement custom backoff logic by using the attempts property in the payload:
Redis SSL/TLS Support
The RedisQueue supports secure connections over SSL/TLS. You can use the rediss:// or tls:// schemes in your connection string:
When using ext-redis, the library automatically handles the tls:// prefix requirement for secure connections.
Signal Handling
Workers gracefully stop when they receive SIGTERM or SIGINT. They finish the current job before exiting.
Monitoring
- Redis: Use
redis-cli MONITORorLLEN qatar:default:ready. - ElasticMQ: Visit
http://localhost:9325for the stats UI.
Testing
Run tests with code coverage:
License
MIT License. See LICENSE for details.
Author
Vaibhav Pandey
- GitHub: @vaibhavpandeyvpz