Apr
5
Most websites has some dynamic pages that make a backend call to a database server such as mysql to retrieve and display data to user’s browser. In my case, I have a website that displays top 20 most voted names on front page of my website. So every time a user visits my website, index.php would make a db call to get this statistical data. When traffic increased, my server performance took a nose dive and I had to raise mysql max connections to support the number of hits it was getting for each user visit but it was only making things worse!
Then, finally I thought of something clever. I renamed index.php (dyanmic version) to index2.php and wrote the following shell script:
cd /home/httpd/vhosts/<www.mywebsite.com>/httpdocs
wget -O index.php http://www.mywebsite.com/index2.php
I saved the above script to a file named /root/publish.sh
And created a crontab entry that would republish index.php every 5 minutes:
*/5 * * * * /root/publish.sh > /dev/null 2>&1
The web server will now simply serve the static version which is now index.php. Data displayed on website is only 5 minutes old, it definitely beats changing code to support caching or buying new hardware to support traffic spike.
I’ve done this with a few other dynamic pages of my website and it’s helped boost server performance 1337%!
Comments
7 Comments so far







Caching is a very good way to reduce performance needs.
Especially for home pages, or static news sections that doesn’t change a lot.
[…] Boost website performance in 15 seconds! - Not exactly caching but simple enough to implement a quick fix. […]
I have visited your site 700-times
I could not find this site in the Search Engines index
I have visited your site 819-times
I have visited your site 704-times
[…] Boost website performance in 15 seconds! - Not exactly caching but simple enough to implement a quick fix. […]