I ran some tests across different PHP frameworks to see how much memory a single page request uses (FatFree, Symfony 1.0x, WordPress, and Drupal). I also asked some colleagues to share what they got. This is based on PHP 5.2 and 5.3 on a mix of Linux, Windows, and Mac. In other words, the results are generalized. A trend is definitely there, but individual results may vary.
Here is a summary of what I found:
- PHP by itself, uses about 256 KB just to spin up and process “hello world”.
- FatFree (http://fatfree.sourceforge.net/), a lightweight framework uses just 1MB-3MB to process a basic page. This framework has a lot of potential. It does not taste like the other fat free products I’ve tried.
- Symfony 1.0x (http://www.symfony-project.org/), is using 8-14MB per page request, depending on how complex the page is. My basic testing of Symfony1.4 with a smaller test application showed similar results (7-9MB locally).
- WordPress weighs in between 21MB and 33MB depending on how many plug-ins are running.
- WordPress 3.1 with minimal plug-ins and Platform theme (this blog) = 23.0 MB
- WordPress 3.1 with minimal plug-ins and custom lightweight theme (friend’s blog) = 20.8 MB
- WordPress 3.1 with plug-ins disabled and Platform theme (this blog) = 21.0 MB
- WordPress 3.1 with many plug-ins = 32.7 MB
- Drupal gets the heavyweight belt coming in between 37.5MB and 76MB!
- Drupal 6 with a BUNCH of modules = 76MB
- Drupal 5 with a more limited collection of modules = 37.5MB
- Drupal 6 with a limited collection of modules = 43MB
The PHP minor version, operating system, and configuration did account for differences but I do not think an order of magnitude is possible. Most of the time the difference was about 5%. I did see one case where it was consistently about 20% more efficient on a workstation vs the QA server. I believe these differences were due to which extensions were turned on in php.ini and PHP 5.2 vs. 5.3.
Not PHP related, but a couple of our apps use a Django admin backend. They consume about 40MB per request. They are used only by our staff and get very low traffic. In this case we are running Python 2.6, Django 1.2.5, Apache 2.2, and mod_wsgi.
Find out how much memory your PHP application is using:
The function is memory_get_peak_usage().
http://www.php.net/manual/en/function.memory-get-peak-usage.php
I tried it and found the output it produces is not so friendly.
xelozz contributed a useful snip which I added to the footer of the templates in each site:
<?php function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } echo convert(memory_get_peak_usage(true)); ?>
I’d like to run a contest to see which site out there uses the most memory per page request?!