Permalink
Browse files

sockets with predis

  • Loading branch information...
repat committed Oct 23, 2014
1 parent a40809e commit d903b2a2ddfcb2ecfe5ac5fbbbbacedabed47959
Showing with 21 additions and 10 deletions.
  1. +5 −5 README.md
  2. +16 −5 index-wp-redis.php
View
@@ -20,10 +20,10 @@ You can install the pecl extension (faster)
```
apt-get install php5-redis
```
-If you don't have the pecl extension installed it will default to use [Predis](https://github.com/nrk/predis)
+If you don't have the pecl extension installed it will default to use [Predis](https://github.com/nrk/predis).
Move the folder wp-redis-cache to the plugin directory and activate the plugin. In the admin section you can set how long you will cache the post for. By default it will cache the post for 12 hours.
-Note: This plugin is optional and is used to refresh the cache after you update a post/page
+Note: This plugin is optional and is used to refresh the cache after you update a post/page.
Move the `index-wp-redis.php` to the root/base Wordpress directory.
@@ -34,16 +34,16 @@ Move the `index.php` to the root/base Wordpress directory. Or manually change t
require('index-wp-redis.php');
?>
```
-In `index-wp-redis.php` change `$ip_of_your_website` to the IP of your server
+In `index-wp-redis.php` change `$websiteIp` to the IP of your server. If you want to use sockets, change `$sockets` to `true` and enter the path of your socket in `$redis_server`.
*Note: Sometimes when you upgrade Wordpress it will replace over your `index.php` file and you will have to redo this step. This is the reason we don't just replace the contents of `index-wp-redis.php` with `index.php`.
-We do this because Wordpress is no longer in charge of displaying our posts. Redis will now serve the post if it is in the cache. If the post is not in the Redis cache it will then call Wordpress to serve the page and then cache it for the next pageload
+We do this because Wordpress is no longer in charge of displaying our posts. Redis will now serve the post if it is in the cache. If the post is not in the Redis cache it will then call Wordpress to serve the page and then cache it for the next pageload.
### Benchmark
------
-I welcome you to compare the page load times of this caching system with other popular Caching plugins such as [Wp Super Cache](http://wordpress.org/plugins/wp-super-cache/) and [W3 Total Cache](http://wordpress.org/plugins/w3-total-cache/)
+I welcome you to compare the page load times of this caching system with other popular Caching plugins such as [Wp Super Cache](http://wordpress.org/plugins/wp-super-cache/) and [W3 Total Cache](http://wordpress.org/plugins/w3-total-cache/).
With a fresh Wordpress install:
View
@@ -40,7 +40,10 @@ function getCleanUrl($secret) {
$debug = true;
$cache = true;
$websiteIp = '127.0.0.1';
-$reddis_server = '127.0.0.1';
+// if you use sockets, set this to true and use $redis_server for socket path
+$sockets = false;
+// in case of sockets something like /home/user/.redis/sock
+$redis_server = '127.0.0.1';
$secret_string = 'changeme';
$current_url = getCleanUrl($secret_string);
$redis_key = md5($current_url);
@@ -60,15 +63,23 @@ function getCleanUrl($secret) {
$redis = new Redis();
// Sockets can be used as well. Documentation @ https://github.com/nicolasff/phpredis/#connection
- $redis->connect($reddis_server);
+ $redis->connect($redis_server);
} else { // Fallback to predis5.2.php
if ($debug) {
echo "<!-- using predis as a backup -->\n";
}
include_once("wp-content/plugins/wp-redis-cache/predis5.2.php"); //we need this to use Redis inside of PHP
- $redis = new Predis_Client();
+
+ if ($sockets) {
+ $redis = new Predis_Client(array(
+ 'scheme' => 'unix',
+ 'path' => $redis_server
+ ));
+ } else {
+ $redis = new Predis_Client();
+ }
}
//Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment
@@ -132,7 +143,7 @@ function getCleanUrl($secret) {
// }
} catch (Exception $e) {
//require('./wp-blog-header.php');
- echo "something went wrong";
+ echo "Something went wrong: " . $e->getMessage();
}
$end = microtime();
@@ -149,4 +160,4 @@ function getCleanUrl($secret) {
echo "<!-- wp-redis-cache-unlimited = " . $unlimited . "-->\n";
}
echo "<!-- wp-redis-cache-debug = " . $debug . "-->\n";
-}
+}

0 comments on commit d903b2a

Please sign in to comment.