Internet was born from static pages. People were creating websites with emacs and vi. With increased popularity of scripting languages and open source databases like MySQL and Postgresql, more and more developers started to use these advanced tools.
CMS systems were build. They made our lives much easier. Instead of altering file contents with editor, the user can simply go to the website admin panel and change page from their.
The speed of loading page generated in PHP with MySQL is much slower than a static page. In addition, on every page request CMS can generate tens or event hundreds of database requests.
With the advances of new web technologies like Jquery and HTML5 we have a chance to get back to the roots. We can create static websites that behaves the same as dynamic ones.
I would like to show you some benchmarks.
In my test I will fetch two small test pages. One with static content and another one generated with PHP and MySQL.
Contents of test.html
Contents of test.php
$handler = mysql_connect('127.0.0.1', 'user', 'password');
$result = mysql_query("SELECT 'Hello World!'");
$row = mysql_fetch_row($result);
In my test I used "ab" command to test web application speed. It stands for Apache Bench – a small application to perform quick test for website speed.
To test static page speed I use the following command:
ab -c 100 -n 10000 http://website.com/test.html
To test dynamic page speed I use the following command:
ab -c 100 -n 10000 http://website.com/test.php
In this test I got the following result. Static pages are at least 3 times faster than dynamic pages generated with PHP and MySQL.
In my production server, at average, ab was able to fetch almost 15k requests per second for test.html static page and 5k requests per second for test.php dynamic page.
Feel free to leave your benchmark results here.