Making php web applications faster by storing db values in cache

Causes for delay in server load time

As the size of data grows, the application starts getting slower. There are numerous reasons for this. Today we are going to see how caching helps to improves web application performance. Caching is a temporary storage of data. Information which has been recently accessed is stored in cache. When the same information is requested again the duplicate content already stored in the cache is displayed to the user. When it is done it is called cache hit and this reduces the load on the server.

For instance, a user wants to view list of tasks assigned to him. The table has 50000 records, each time we need to query all records and display it to the user. This increases server load, takes up processing time hence gives a bad user experience. To overcome this, we use caching.

“Caching stores the result in a dynamic memory, and display results to the user from the memory instead of hitting the server each time”

What is memcached

Memcached is a distributed memory caching system extension available for using in php application development. Memcached reduce the number of server requests and hence handle many requests simultaneously improving customer satisfaction by providing seamless access to data. Memcached stores each query value with a key and for subsequent db calls, it identifies the key and provides the desired information instantly.

“Memcached is a powerful distributed memory object caching system”

Installing memcached

Install memcached extension to fetch results from db and store in a memcached object. Installing memcached is the same as other extensions. You can add the extension by compiling with php or by loading the “.dll” file to the system. Once the memcached is installed, it automatically starts when the server boots. Libmemcached library is required for installing the memcached file.

evoluer, best popular company in coimbatore for php, software, web and cross/multi platform mobile application development about us


In addition to php, MYSQL should also be available for using memcached. You can use “ sudo apt-get install mysql-server php5-memcached ”. You need to restart apache after installation or you can manually download the dll file and add it in the php.ini file. You will need to restart apache here also.

Verifying installation

You can check the installation by using phpinfo(), which calls the php to collect information from the server and display. You can enter the page domain name or IP address with a “ /info.php “ extension. Then move to the memcached section and you can find memcached active. Then we can check whether memcached is storing data. Create a file with name “cache_test.php”. Add a memcached object and store it in a variable with a defined path location for the php to access. Next we create a query for the key named as “Test”, which is stored in a variable named “Result”.

When we check the working, memcached would fetch the result if data is available. If the data is not available it would connect to the server database or the main storage and fetch data and store the results in its memory. Subsequent fetches display the result from the memcached object.

evoluer, best popular company in coimbatore for php, software, web and cross/multi platform mobile application development about us


Activating memcached and storing the data in this duplicate location reduces server load time and improves user experience. For detailed information regarding reducing server load time and using memcached, contact us