celery-yii is a Yii extension to dispatch Celery tasks.
It is a wrapper to celery-php, released under the same BSD license.
This extension is unrelated with the Yii AMQP extension. In case you don't actually need Celery, but just communicating via AMQP you may want to check that.
Requirements ¶
- Yii 1.1 or above (tested on Yii 1.1.9)
- Celery (tested on 2.5.5 and on 3.0.4)
- PHP AMQP extension v1.0 or above (http://www.php.net/manual/en/amqp.setup.php)
celery-php is released within celery-yii
Be sure that both Celery and celery-php are installed and working.
This means:
install Celery with ~~~ pip install Celery ~~~
install the PHP AMQP extension following these instructions. Note that celery-php contains a script to automatically do that.
configure Celery as celery-php requires, i.e. adding the following configuration: ~~~ CELERY_RESULT_SERIALIZER = "json" CELERY_TASK_RESULT_EXPIRES = None ~~~ Note: at the time of writing (2012-06-16) the documentation of celery-php reports a bad configuration parameter.
Usage ¶
Download the package and decompress it in the protected/extensions
directory.
Add the following configuration to protected/config/main.php
:
'components'=>array(
...
'celery' => array(
'class' => 'ext.celery-yii.ECelery',
// login, password and virtual host
'login' => 'myuser',
'password' => 'mypass',
'vhost' => 'myvhost',
// probably, you don't need to change host & port
//'host' => 'localhost',
//'port' => 5672,
// almost surely, you don't need to change exchange & binding
//'exchange' => 'celery',
//'binding' => 'celery',
),
...
Send tasks to Celery:
$result = Yii::app()->celery->postTask('tasks.add', array(2,2));
You can either ignore $result
if you just want to send async tasks to the backend, or use $result
exactly as explained in celery-php, for instance:
$result->get();
if($result->successful())
{
echo $result->result;
}
Enjoy!
Resources ¶
- Project page
- Forum page
- Based on celery-php
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.