Yii2 Queue
Run tasks asynchronously via queues in Yii 2 with pluggable backends.
Repository Health
Technical Analysis
yii2-queue is an extension for the Yii Framework 2.0 that lets applications run tasks asynchronously by pushing jobs onto a queue and processing them with background workers. It offers a single unified API on top of many queue backends, so switching from a database queue in development to Redis or RabbitMQ in production is a configuration change rather than a rewrite.
The extension supports DB, Redis, RabbitMQ, AMQP, Beanstalk, ActiveMQ, and Gearman drivers, and includes features like delayed jobs, priorities, retries with configurable attempts, and CLI worker commands for running and monitoring the queue.
What You Get
- A unified queue API with interchangeable backend drivers
- Drivers for DB, Redis, RabbitMQ/AMQP, Beanstalk, ActiveMQ, and Gearman
- Delayed execution, job priorities, and configurable retry attempts
- Console commands to run, listen to, and monitor workers
- Events and a log behavior for observing job lifecycle
- Pluggable serializers for job payloads
Common Use Cases
- Sending emails and notifications outside the request cycle
- Processing uploaded media or generating reports in the background
- Distributing heavy work across multiple worker processes
- Scheduling delayed or retryable tasks in a Yii 2 application
Under The Hood
Architecture - The core Queue component (src/Queue.php) defines push, delayed and priority variants, and dispatches jobs implementing JobInterface/RetryableJobInterface. Backend behavior is isolated behind driver classes under src/drivers/ (amqp_interop, beanstalk, db, file, gearman, redis, sqs, stomp, sync), each extending a common base so the public API stays identical across backends. Job lifecycle is surfaced through events (PushEvent, ExecEvent, JobEvent) and a LogBehavior, while src/cli/ provides the console worker commands. Tech Stack - Almost entirely PHP (98%+), built on yiisoft/yii2, with optional per-driver dependencies (e.g. redis, amqp interop libraries) pulled in only when a given backend is used. Payloads are handled through pluggable classes in src/serializers/. Code Quality - The repository ships CI build and static-analysis workflows, a PHPUnit test suite, Docker-based integration testing for the message brokers, and a Makefile, reflecting a mature and well-tested codebase. API Design - Usage is ergonomic: define a job class with an execute() method, push it via Yii::$app->queue->push(new MyJob()), and run a worker from the CLI. Driver selection is purely declarative in application configuration, keeping application code backend-agnostic.