Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a client ecommerce portal hosted on a Dedicated server and the issue is as there are concurrent search requests from the database, the database access time is getting higher. I am using Apache+ NGINX. I am just thinking to cache all the search result pages of a limited set of time so that if second time the same search query is requested then rather than quering the database it would take the data from the cache. The pages are in PHP. Kindly suggest a good way to do that. Thank you!

share|improve this question
up vote 4 down vote accepted

memcache is a very common solution for this, and is supported in PHP's standard library assuming your PHP setup has that module available. See for the API. You will notice that there is a second standard module that interfaces with memcache too - the newer module is called memcached and may support features that the other does not. See this question and answer for a run down of the pros and cons of the two.

Before you start adding the extra layer of complexity of caching (actually it need not be complex, but it is an extra thing that could go wrong and needs careful thought to implement effectively/efficiently), make sure that you have analysed the queries that are being made to make sure your data is well indexed for them. If there are common search type that are causing full table scans but could be made to use index searches you could reduce your overall load considerably. Also ensure that you have enough RAM - if your DB is being slow due to hitting disk too often because it doesn't have room to keep your app's common working set in its page cache then you don't have enough RAM for memcached to be particularly useful either.

share|improve this answer

Apache has a module for caching (mod_cache), it can cache your site's served contents More info at:

You could let recurring requested pages expire at a longer timeframe using Apache's mod_expires, but that's on a client's level.

Nginx has a possibility to cache use *proxy_cache* and *proxy_cache_path*.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.