

Ask HN: PHP vs Static HTML processing  - rumpelstiltskin

How much more processing does a dynamic PHP page require over the same page in static HTML?
======
Scott_MacGregor
If you are asking about this because you are concerned about processor load
affecting the number of clients that can connect, in Apache 2.2 the amount of
memory and the Apache settings will have some bearing on this also.

For instance, the Apache MaxClients setting formula many follow is, MaxClients
= Total RAM dedicated to the web server / Max child process size.

Child process size for serving static file is about 2-3M. For dynamic content
such as PHP, it may be around 15M. More memory = more connections.

Apache server performance can be improved by adding additional hardware
resources such as RAM, faster CPU etc. but you might be able to achieve the
same results with some simple custom Apache configurations on your current
setup.

Here is a link for Apache 2.2.3 if you are interested:
[http://cloudservers.rackspacecloud.com/index.php/Configuring...](http://cloudservers.rackspacecloud.com/index.php/Configuring_Apache_for_Maximum_Performance)

------
pedalpete
in php, you can output the time it takes to complete a given task.
Unfortunately, you can't do this with HTML.

However, you could set the timer in php, and then compare having php build the
html vs the php page outputting the html.

That way you are also only comparing the time it takes for php to load the
difference, and not differences in how web servers deal with different mime-
types, etc.

I suspect you are talking in the less than 1 millisecond range difference
though.

------
tjpick
if it's the simple stuff like variable substitution and simple loops, php is
actually not too bad IMO. When you start doing database and http calls then
your performance gets a lot worse.

A static page is obviously going to be faster though.

~~~
rumpelstiltskin
How much worse? 5 times? 10 times? Let's say it's a wordpress blog.

~~~
tjpick
how long is a piece of string?

It depends on the time that your database query or http call takes, and how
much data you are returning, and how much processing you have to do on it. A
well written query or call won't have too much of a negative impact, maybe
making the page two times slower than a static. A poorly written query
strategy could make a page a thousand times slower.

xdebug and timing code are helpful.

