Redis is frequently used as a caching layer for web applications to improve its performance. In PHP 5.x, if one wants to use Redis, the redis extension needs to be installed and enabled first.
This post will show how to install and enable redis extension on Windows with PHP 5.X. Basically there are two dlls to be downloaded: php_redis.dll
and php_igbinary.dll
.
Below are detailed steps
- Go to http://windows.php.net/downloads/pecl/releases/redis/2.2.7/ and find the respective php_redis zip matching your environment.
- Go to windows.php.net - /downloads/pecl/releases/igbinary/2.0.1/ and find the respective php_igbinary zip matching your environment
- Unzip these two files and copy them to the ext folder of PHP.
- Next step is to update the
php.ini
file so that it can be loaded and enabled once the Apache server restarts. Below needs to be added in the php.ini file. (Note: The order matters here, php_igbinary.dll should come before php_redis.dll).
extension=php_igbinary.dll extension=php_redis.dll​
- Save php.ini and now restart the Apache server and you should see Redis extension shown up in
phpinfo()
. - Now you can write code to access Redis server like below.
$redis = new Redis(); //Connecting to Redis $redis->connect('localhost', 6357); $redis->auth('password'); if ($redis->ping()) { echo "OK"; }​
Hope this helps you if you wanna use Redis in your PHP application.
What year is this?