This is an app that integrates PHP-Resque into the Elefant CMS, so you can easily add background tasks to your apps.
PHP-Resque requires Redis 2.2+ as well as the PCNTL extension.
- Install the app into the
apps/folder. - Copy
apps/resque/conf/config.phptoconf/app.resque.config.phpand edit the settings there.
First you need to initialize the app for adding jobs to the queue:
<?php
// Initialize the Resque app
$this->run ('resque/init');
?>After initializing the app, you can call Resque::enqueue() anywhere after that.
<?php
// Enqueue a job after calling resque/init
Resque::enqueue ('queue_name', 'JobName', array ('arg1' => 'value'));
?>Defining a job in Resque is done by creating a class named after the job name
with a perform() method that will be called on to perform the job:
<?php
class JobName {
public function perform () {
printf ("Test job, received: %s\n", $this->args['arg1']);
}
}
?>Save this to your app's lib/ folder, e.g., apps/myapp/lib/JobName.php.
To start running the workers, use the following command:
$ ./elefant resque/runYou can also override most of the settings by passing parameters to the command, including:
-
--helpDisplay help output -
--logging=(off|normal|verbose)Set the logging level -
--pid-file=./resque.pidSet the PID file -
--queue=queue_nameSpecify the queue to watch -
--sleep-interval=5Seconds to sleep for -
--workers=5Number of workers to spawn