Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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 http://www.php.net/manual/en/book.memcache.php 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
add comment

Apache has a module for caching (mod_cache), it can cache your site's served contents More info at: http://httpd.apache.org/docs/2.1/mod/mod_cache.html

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
add comment

Your Answer

 
discard

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.