Background jobs with php and resque: part 3, installation
As said in part 2, we’ll use php-resque for our queue system. In this part, I’ll explain how to install all the tools needed to run php-resque, a port of Resque.
Resque (pronounced like “rescue”) is a Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.
Obviously, we’ll also need to install Redis, and its php extension. The full list of tools to install :
Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
It’s a very fast key-value database, since it’s stored in the RAM. You can also use it for caching, or storing sessions.
Check out their download page to download and install the latest version. Installation instruction are on their website. Once installed, don’t forget to start the server.
php-resque is a php port of resque, and provides much the same features as the original version.
Download the latest version in zip, or clone the repo with
git clone git://github.com/chrisboulton/php-resque.git
That’s pretty much all, it’s just a library, nothing to compile or install. Just put the folder somewhere in your project.
The phpredis extension provides an API for communicating with the Redis key-value store
Again, installation instructions are in the README.
phpredis is not the only way for php to communicate with redis. There are many other library like redisent, rediska, predis and redisentwrap that can do the same thing, but phpredis is the fastest, since it’s a native php extension. (benchmark)
Redisent is included in php-resque, and is the API used by php-resque to communicate with redis. You’ll have to edit some files in the library to get it working with phpredis.
git clone git://github.com/kamisama/php-resque-ex.git
An extra step is needed to download all the required libraries. If you’ve chosen to download the archive, first extract it. We’ll then need to
cd into the php-resque-ex folder:
Then download composer and download the dependencies
curl -s https://getcomposer.org/installer | php php composer.phar install
Process Control (PCNTL) implements the Unix style of process creation, program execution, signal handling and process termination
It’s used to fork php process.
If it’s not already installed :
- Download the php sources corresponding to your php installation
- Uncompress the file
tar -zxvf php-x.x.x.tar.gz
- Go into the ext/pcntl folder
- Configure, compile and install it
sudo phpize && ./configure && make install
extension=pcntl.soto your php.ini
- Restart apache
/etc/init.d/apache2 restart # for linux apachectl restart # for OS X
Next time …
In part 4, we’ll go into the heart of the subject : implementing the queue system and background jobs into your application.