Using Memcached in PHP
Memcached is a high-performance open-source caching solution, generally used to improve web application performance by avoiding round-trips to RDBMS, to know more about memcached read Faster Webapps With Memcached.
In this article we'll discuss about installing and using memcached in PHP. A PHP extension is available for working with memcached with requires the C libmemcached library to be present.
Download the latest release of PECL memcached PHP extension from http://pecl.php.net/package/memcached and unpack it.
Compile & install. Now, you can check the availability of the extension using phpinfo().
If you are running Ubuntu variant or Debian & running PHP 5, just run the following to install the PHP extension:
Memcached PHP extension provides an OOP interface, which is very easy, follow the code sample below to get an idea of the usage.
That was a very basic example, next let us look at more advanced usage:
You may store user session data in Memcached instead of regular file handler, which make sessions faster & independent of the server where the request lands (in case you have multiple servers under a load balancer). Here's what you need to do to use memcached for session.
In php.ini set the following:
The session key names are prefixed with memc.sess.key.
|All times are GMT +5.5. The time now is 02:50.|