Load time of static HTML and dynamic PHP pages

I was wondering what's the difference in a webserver load when a user requests a static HTML page and dynamic PHP page. It's obvious that PHP scripts must generate higher load than HTML pages but the question was whether it matters. If the difference was really low it would be better to generate each page with PHP because you wouldn't have to care about caching or writing Apache rewrites.

I made a quick test. Using standard ab tool (Apache Benchmark) I compared mean times required for one request in two situations:


First, I sent 1000 requests from my computer to the remote website.

Result is quiet surprising. Mean time for static HTML pages is 60 ms and 188 ms for dynamic PHP. One would guess that the difference will be more significant.

When I used ab from my computer to another the biggest delay was made on the way to the server and on the way back to me (for more information check out Round-trip delay time. So, this measurement was basically wrong.

Next time I run ab directly on the production webserver which eliminated latency and measured only the time necessary to run PHP scripts or to retrieve a HTML page.

Again 1000 requests. This time the chart looks much better than the first one.

The HTML bar is not a mistake. Mean time for static HTML pages is only 0.515 ms and 102 ms for dynamic PHP.

Retrieving static HTML was 200 times faster than processing the PHP script.


The question is: Does it really matter? From users point of view 0.5 ms or 100 ms is the same. But for webserver it matters a lot. If you happen to have 100 users requesting a page in the same second it would be very important if the webserver could server each request in 0.5 ms than 100 ms. Not only in terms of connections to the database but also webserver would have to create a thread or proccess for each request, start PHP interpreter, allocate memory, eventualy compile scripts, etc. and this takes some time.

So the answer is yes. I think caching makes sence and even if you can't cache whole page like I did you can cache at least some parts. Of course, sometimes it's not that simple or when you have a page which is changing very often it's probably easier to generate it's content every time.

blog comments powered by Disqus