Starting Workers


Supervisor is a process monitor for Linux. It automatically starts console processes. On Ubuntu it can be installed with this command:

sudo apt-get install supervisor

Supervisor config files are usually available in /etc/supervisor/conf.d. You can create any number of config files there.

Here's an example:

command=/usr/bin/php /var/www/my_project/yii queue/listen --verbose=1 --color=0

In this case Supervisor should start 4 queue/listen workers. The worker output will be written to the specified log file.

For more info about Supervisor's configuration and usage see its documentation.

Note that worker daemons started with queue/listen are only supported by the File, Db, Redis, RabbitMQ, AMQP Interop, Beanstalk, Gearman and AWS SQS drivers. For additional options see driver guide.


Systemd is another init system used on Linux to bootstrap the user space. To configure workers startup using systemd, create a config file named yii-queue@.service in /etc/systemd/system with the following content:

Description=Yii Queue Worker %I
# the following two lines only apply if your queue backend is mysql
# replace this with the service that powers your backend

ExecStart=/usr/bin/php /var/www/my_project/yii queue/listen --verbose


You need to reload systemd in order to re-read its configuration:

systemctl daemon-reload

Set of commands to control workers:

# To start two workers
systemctl start yii-queue@1 yii-queue@2

# To get the status of running workers
systemctl status "yii-queue@*"

# To stop a specific worker
systemctl stop yii-queue@2

# To stop all running workers
systemctl stop "yii-queue@*"

# To start two workers at system boot
systemctl enable yii-queue@1 yii-queue@2

To learn all features of systemd, check its documentation.


You can also start workers using cron. Here you have to use the queue/run command.

Config example:

* * * * * /usr/bin/php /var/www/my_project/yii queue/run

In this case cron will run the command every minute.

The queue/run command is supported by the File, Db, Redis, Beanstalk, Gearman, AWS SQS drivers. For additional options see driver guide.