CLI Command examples on this page are always provided without the --application (shorthand -A) argument,
assuming you’re running these commands in a connected folder (at creation or using the dotcloudconnect command).
For more details on connected folders, see Migrating to the CLI 0.9.

As you write your application you will certainly need to execute some
asynchronous tasks. It could be anything that requires some form of (lengthy)
processing: image resizing, archiving, document analysis...

These jobs could be run from the same machine were your application server is,
but best practices advise you to do this on a different machine because:

You avoid impacts from the background jobs to your application;

Decoupling parts of the application eases maintenance and scaling.

dotCloud makes it very easy to architecture your application on different
“Services” each one with a different role and on a different machine.
Background jobs match perfectly this feature: we will be using a Redis service
to queue background jobs launched on one PHP service and executed on a second
PHP service:

The first PHP instance creates and enqueues jobs on Redis, which are dequeued
and performed on a second PHP instances. This architecture is very scalable: you
can have as much as PHP instances you want to perform or enqueue jobs and Redis
could be replicated in a master/slave setup.

All of this is done with the help of a PHP library called PHP-Resque, which implements the job queues
on Redis and offers an easy way to create and perform jobs. PHP-Resque is
actually the PHP port of the Resque
Ruby library used at GitHub for all their asynchronous
jobs since 2009.

We are going to see how to use PHP-Resque through a simple web application. As a matter of fact the application
also uses CodeIgniter a very straightforward web
framework.

This calls a “parsing” function which returns an associative array with the
Redis host, port and password. It is just a sequence of file_get_contents, json_decode and array_combine calls with some
error handling:

Notice the “proctitle” requirement on the “workers” service. This is an optional
dependency of PHP-Resque to rewrite unix process names so you can quickly see
what the workers are doing when you run something equivalent to “ps aux”. This
requirement correspond to a PECL package that will be installed automatically
when you push the code on dotCloud.

These three lines tell Supervisor how the background process should be
launched:

In the directory “/home/dotcloud/current/” (this is where the dotCloud
builder will install your application);

Using the command: “php index.php jobs run_workers”;

With the environment variable QUEUE set to * (you can use multiple queues
with PHP-Resque and only launch workers on a specific queue), with * workers
will process jobs on any queue.

stopsignal=QUIT

This is a hint to tell Supervisor to use the SIGQUIT Unix signal when it tries
to gracefully stop the workers (instead of using the default SIGTERM
convention). Since the workers will be stopped and started each time you push
your code on dotCloud, but it is interesting to be able to gracefully interrupt the
current jobs.

PHP-Resque is very easy to get working on dotCloud. Let’s review what we did
here:

Connect PHP-Resque to Redis by using environment.json and Resque::setBackend("host:port");

Authenticate to Redis by using: Resque::redis()->auth("password");

Launched some workers by using the PHP-Resque worker
script resque.php;

Created a job class with a perform() method;

Enqueued some jobs with: Resque::enqueue(QueueName,ClassName,Args).

If you want to dig into the short PHP files used here, you can clone the
application and start to look into the application/controllers and
application/models directories where the interesting parts are.