Boost website performance in 15 seconds!

April 5, 2007 |

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

  1. GMT on April 5, 2007 6:16 pm

    Caching is a very good way to reduce performance needs.

    Especially for home pages, or static news sections that doesn’t change a lot.

  2. Boost PHP Performance : lxpages.com blog on July 5, 2007 4:08 pm

    […] Boost website performance in 15 seconds! - Not exactly caching but simple enough to implement a quick fix. […]

  3. Visitor319 on July 12, 2007 2:16 pm

    I have visited your site 700-times

  4. Visitor304 on July 12, 2007 2:17 pm

    I could not find this site in the Search Engines index

  5. Visitor325 on July 25, 2007 4:43 am

    I have visited your site 819-times

  6. Visitor913 on August 17, 2007 4:42 pm

    I have visited your site 704-times

  7. Come incrementare la velocità di php : sastgroup.com on November 21, 2007 2:24 pm

    […] Boost website performance in 15 seconds! - Not exactly caching but simple enough to implement a quick fix. […]

Name

Email

Website

Speak your mind

  • Categories

  • Sponsors