• Announcements

    • MannDude

      Current state of vpsBoard   02/04/2017

      Dear vpsBoard members and guests:

      Over the last year or two vpsBoard activity and traffic has dwindled. I have had a change of career and interests, and as such am no longer an active member of the web hosting industry.

      Due to time constraints and new interests I no longer wish to continue to maintain vpsBoard. The web site will remain only as an archive to preserve and showcase some of the great material, guides, and industry news that has been generated by members, some of which I remain in contact to this very day and now regard as personal friends.

      I want to thank all of our members who helped make vpsBoard the fastest growing industry forum. In it's prime it was an active and ripe source of activity, news, guides and just general off-topic banter and fun.

      I wish all members and guests the very best, whether it be with your business or your personal projects.


Search the Community

Showing results for tags 'redis'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • vpsBoard
    • Announcements & Contests
    • Industry News
  • Virtual Private Servers
    • General Talk
    • Operating a VPS Business
    • Tutorials and Guides
    • Questions and Answers
  • The Lounge
    • The Pub (Off topic discussion)
    • Coding, Scripting & Programming
    • SBC, ARM, Home Automation
  • Marketplace & Reviews
    • Reviews
    • VPS Offers
    • Other Offers
    • Service Requests

Found 2 results

  1. This is my second post for php based projects. My first thread is about an IoT plattform for Ardunio clients. This post is about creating a simple web interface for a redis key/value store. If you want to install your own redis database you can use this tutorial: I will use following php frameworks to get the rest interface done: Slim, CorSlim, Predis. All the server and client code will be available at github: https://github.com/wlanboy/php-redis-rest-service a) Server We first have to enable CORS support to enable clients of other domains to use our service: require ('CorsSlim/CorsSlim.php'); $app->add(new \CorsSlim\CorsSlim()); $corsOptions = array( "origin" => "*", "exposeHeaders" => array("Content-Type", "X-Requested-With", "X-authentication", "X-client"), "allowMethods" => array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS') ); $cors = new \CorsSlim\CorsSlim($corsOptions); $app->add($cors); After that we have to get a connection to our local redis instance: $app->container->singleton('redisclient', function() { $client = new Predis\Client('tcp://'); return $client; }); And define the routes: //Redis routes $app->get('/key/:id', 'getKey'); $app->post('/key', 'addKey'); And implement them with the help of the Predis framework: function getKey($id) { $app = \Slim\Slim::getInstance(); $client = $app->redisclient; try { $value = $client->get($id); $temp = (object) [ $id => $value ]; echo json_encode($temp); } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } } Done :-) b) Client I use a simple Ajax JS script for the client. The most simple way to create the GET and POST requests. We first defien a data object which is able to create JSON output: function KeyValue(key, value) { var kv = {"key":key, "value":value}; kv.toJsonString = function () { return JSON.stringify(kv); }; return kv; }; And a simple send method that reads form data, sends it to the rest service and prints the response: function sendMessage() { var key = document.getElementById("postkey").value; var value = document.getElementById("postvalue").value; if (value == "") { jQuery.ajax({ type: "GET", url: "https://rest-api/key/"+key, contentType: "application/json; charset=utf-8", dataType:"json", success: function (data, status, jqXHR) { output = document.getElementById("output"); output.innerHTML = JSON.stringify(data); document.getElementById("postkey").focus(); }, error: function (jqXHR, status) { output = document.getElementById("output"); output.innerHTML = status; document.getElementById("postkey").focus(); } }); } } Using GetElementByID + value to get the input. Creating a jQuery ajax request and add the key to the url to get the variable stored in redis. Same with the POST request to store the value of a variable in redis: else{ var contact = KeyValue(key,value); jQuery.ajax({ type: "POST", url: "https://rest-api/key", contentType: "application/json; charset=utf-8", data: contact.toJsonString(), dataType:"json", success: function (data, status, jqXHR) { output = document.getElementById("output"); output.innerHTML = JSON.stringify(data); document.getElementById("postkey").focus(); }, error: function (jqXHR, status) { output = document.getElementById("output"); output.innerHTML = status; output.innerHTML += "<br/>"; output.innerHTML += jqXHR.responseJSON; document.getElementById("postkey").focus(); } }); } This time with a data line to get the JSON data of the contact element. Same JSON.stringify to get the string representation of the json object. Done. Simple server & client example to use a redis database without any binary client. Simple HTTP requests to use the redis service. I will add additional methods to the rest service to add the other redis commands too.
  2. Hey everyone. Thought I should share this method of speeding WordPress up dramatically without much configuration. This is the caching method used over at Gatsby and any WordPress based client sites I maintain. As the cache is in-memory, it handles surges of traffic very well. Want to see how it handles? Head over to Gatsby. Requirements: The ability to follow simple instructions Root access to your server (Just incase this is picked up by Google) About 15 minutes of your time This tutorial assumes you already have WordPress set up and ready to roll. I personally use this in conjunction with APC. It should work with other caching methods as well, but your milage may vary. 1. Back your stuff up Although nothing we're going to be doing will touch your databases and whatnot, it's probably a good idea to make sure you're able to revert to how things were originally. Just incase you completely fudge something up. In all honesty, you should have robust backups in place already. If not, here's your gentle reminder to get backups set up. Also - It's not a backup unless you're able to restore it easily in an emergency. 2. Add a Repo This is genuinely the most taxing part of the process, although it's relatively simple. The issue is that most Linux distros have pretty outdated versions of Redis in their repositories. Although you could just install the respective .deb/.rpm, it's a good idea to get a frequently updated repository added to your system just incase an exploit is found in Redis. If you're running Debian Linux I personally recommend you use the DotDeb repository If you're running a RedHat based Linux distro, I personally recommend you use Remi Collet's repository Follow the respective instructions on each site! 3. Install Redis If you're running a Debian based Linux distro apt-get install redis If you're running a RedHat based Linux distro yum install redis Once installed, you can fire up Redis /etc/init.d/redis start OR /etc/init.d/redis-server start 4. Make WordPress Use Redis Here's the last step. We're going to need a couple of files to make WordPress interact with Redis. The idea is that we want to use a new index.php, so that every single valid request hits Redis before asking WordPress to regenerate the page. To do that, we'll have to move the original index.php mv index.php backup_index.php You'll then need to grab predis.php so PHP can interact with Redis wget http://uploads.staticjw.com/ji/jim/predis.php Finally, grab the new index.php wget http://pastie.org/pastes/7953263/text -O index.php If all goes well, load up your WordPress site and pages should appear. If not, you've probably done something wrong. Final Statements I do not claim any credit for this caching method, all of which goes to Jim Westergren. In regards to security, it only displays the cached pages if the visitor isn't logged in - That means that whilst you're logged in pages may load slower. To refresh a page's cache, force a page reload (F5). Pages aren't regenerated if you're simply clicking through pages.