Yii 1.1: yii-resque

php-resque wrapper for Yii, build as component and command console

Yii Resque

Yii resque is a component for Yii to queue your background jobs, this component based on php-resque with some enhancement for support phpredis.


  • php pnctl extension.
  • Redis.io
  • phpredis extension for better performance, otherwise it'll automatically using Credis as fallback.
  • Yii Framework >1.1.x


  • Copy files to each folder
  • Add to your config.php and your console.php
            'class' => 'application.components.yii-resque.RResque',
            'server' => 'localhost',    // Redis server address
            'port' => '6379',           // Redis server port
            'database' => 0             // Redis database number
  • Change path for Yii framework folder in components/yii-resque/bin/resque

How to

Create job and Workers

You can put this line where ever you want to register the queue

Yii::app()->resque->createJob('queue_name', 'Worker_ClassWorker', $args = array());

Put your workers inside Worker folder and name the class with Worker_ as prefix, e.g you want to create worker with name SendEmail then you can create file inside Worker folder and name it SendEmail.php, class inside this file must be Worker_SendEmail

Start and Stop workers

Run this command from your console/terminal :

    yiic rresque start


    yiic rresque stop

Project Resource

Total 14 comments

#19734 report it
jinren at 2016/01/10 06:42pm
Supervisord won't work with this

Supervisord won't work with this because your process is a daemonizing process : [http://supervisord.org/subprocess.html].

#19732 report it
jinren at 2016/01/08 09:57pm
Process dying ?

@TheBee I'm looking into supervisord now. Just curious but why would yii-resque die if it's not even being used ? Is there any way to address that ? Thank you :-)

#19718 report it
jinren at 2015/12/27 04:36pm

OK, will look into it.

#19717 report it
TheBee at 2015/12/27 04:33pm
How to keep worker alive

@jinren The best trick to keep the worker alive is using Process control system like supervisor in ubuntu, it'll automatically revive the worker if it stop suddenly and also if there is an error it'll put some logs so you can trace the bug easily.

#19714 report it
jinren at 2015/12/26 03:57pm
Server dies after some time... ?

Got it working and yii-resque server is supposed to be active but if I leave it for months as I just did (app hasn't launched yet, working on other sections), then it "dies" and the worker gives me an exit code of 255. Any ideas how to prevent this and keep it "alive" ? I'm not sure what the "timeout" duration is. A server should be reliable and keep running and not just cop out when it feels like it.

Thanks !

Also posted here : http://www.yiiframework.com/forum/index.php/topic/69068-yii-resque-extension-issue/

#16531 report it
M0ka at 2014/03/03 03:54am

Thank you for your notice, your solution is better for performance.

#16530 report it
TheBee at 2014/03/03 03:48am

As you mention it, configuration that you use in main.php will never loaded on your resque worker since it using console.php instead, so you need to import your require class on console.php or using


on setUp function inside your worker class to avoid importing all classes on every jobs.

#16529 report it
M0ka at 2014/03/03 03:39am
I figured it out

Thank you so much I figured it out by this solution, I added these codes to the config/console.php

'import' => array(

and for any database queries, I had to add the configurations to the config/console.php too

#16526 report it
TheBee at 2014/03/03 12:55am
Resque Log

is there any error thrown when you start the resque or sending a job on your resque log file? log file location is :

#16521 report it
M0ka at 2014/03/02 02:31am

Yes I have Email.php and the class name Worker_Email, and inside this class, I made 3 functions, setup(), perform() and tearDown(), and I have put my code that I want it to be excuted into the perform() function, which is an update to a mongoDB, and I have added the config of the mongoDB into config/console.php

Is there anything missing of my scenario? Thank you so much in advance :)

#16517 report it
TheBee at 2014/03/01 03:30pm

Not sure about this, just for re-check, are you sure have file "Email.php" inside Worker folder? and this file is contain "Worker_Email" class.

#16513 report it
M0ka at 2014/03/01 07:09am

Thanks for your reply.. when I did what you've said, I got it work, now I had this on my log file

This on resque log

[2014-03-01T11:08:10+00:00] got {"queue":"default","id":"414c8b2770dc95584a8a5f86ca2195e1","class":"Worker_Email","args":[[]]}
[2014-03-01T11:08:10+00:00] Processing ID:414c8b2770dc95584a8a5f86ca2195e1 in default
    "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Internal Server Error</title>
<style type="text/css">
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
<h1>Internal Server Error</h1>
<h2>Invalid argument supplied for foreach()</h2>
An internal error occurred while the Web server was processing your request.
Please contact the webmaster to report this problem.
Thank you.
<div class="version">
2014-03-01 11:08:10 </div>

and this on application

2014/03/01 11:08:10 [error] [php] Invalid argument supplied for foreach() (/var/www/yii/framework/YiiBase.php:411)
Stack trace:
#0 protected/components/yii-resque/lib/Resque/Job.php(155): class_exists()
#1 protected/components/yii-resque/lib/Resque/Job.php(187): Resque_Job->getInstance()
#2 protected/components/yii-resque/lib/Resque/Worker.php(245): Resque_Job->perform()
#3 protected/components/yii-resque/lib/Resque/Worker.php(208): Resque_Worker->perform()
#4 protected/components/yii-resque/bin/resque(131): Resque_Worker->work()
#5 protected/components/yii-resque/bin/resque(103): startWorker()

Can you please help me with it?

#16512 report it
TheBee at 2014/03/01 05:12am
Run in protected folder

You should run it from protected folder, so it'll be look like this :

/var/www/your-project/protected/yiic rresque start
#16508 report it
M0ka at 2014/02/28 10:01pm
This is confusing

I am trying to add all what you posted literally but still cant make it work by this command

yiic rresque start

first it said no yiic command known, so i tried to make it /var/www/yii/framework/yiic but still doesn't work. cant start rresque at all, could you please help?

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet