Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Speeding up Existing Apps with a Redis Cache
Jul 28, 2015 @ 15:27:06

The SitePoint PHP blog has posted a tutorial that want to help you speed up your applications with Redis, adding in caching to help reduce the overall processing load your app has to expend.

The application in question, when executing a query, runs off to Diffbot’s API and makes it query the dataset. The subset is then returned and displayed. This can take up to 5 or so seconds, depending on the busyness of Diffbot’s servers. While the situation will undoubtedly improve as they expand their computational capacity, it would be nice if a query executed once were remembered and reused for 24 hours, seeing as the collection is only refreshed that often anyway.

Considering the fact that implementing this cache costs us literally nothing (and actually reduces costs by reducing strain on the servers), adding it in is an easy win, even if it weren’t used as often as one would hope. There is no reason not to add it – it can only benefit us.

He helps you get Redis up and running as a service on the local system and installing the Predis, the PHP library you'll use to talk with Redis for setting and getting the cached information. He includes a few code snippets showing how to send the search off to the DiffBot API, return the results and push them into the cache as serialized data with a day long timeout. He also mentions the phpiredis extension to reduce some of the overhead that could be cause by using a PHP library versus an extension.

tagged: speed performance redis cache tutorial introduction predis phpiredis

Link: http://www.sitepoint.com/speeding-up-existing-apps-with-a-redis-cache/


Trending Topics: