Every PHP framework has some overhead compared to plain PHP. This overhead will slow down content delivery, but on the other hand frameworks can speed up application development.
To get the costs of using PHP and PHP based frameworks, I made some simple benchmarks comparing apache delivering a static html file, a plain PHP file, and rendering the same pages from tk_self and CodeIgniter. The following file has to be delivered from tk_self, CodeIgniter and as static file from apache:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <h3>hello world</h3> </body> </html>
For the plain PHP file the hello world line was replaced by a simple echo command:
<?php echo 'hello world' ?>
For benchmarking I have used the local apache server (with mod_php) and the apache ab tool:
$ ./ab -n 1000 -c 1 http://try.tkself.test/
So every run sends 1000 requests with a concurrency of one: I don't wanted to test the scalability for parallel requests, but just the overhead for invoking PHP. Every run was repeated three times and the best value has been used (because on a multi-tasking system the best value is the most representative one for the real performance):
| Delivery method | req/sec | ms/req | relation |
|---|---|---|---|
| static file | 2811 | 0.4 | - |
| php file | 1427 | 0.7 | 100 % |
| tk_self | 490 | 2.0 | 34 % |
| CodeIgniter | 82 | 11.9 | 5.7 % |
Using PHP instead of static files reduces the performance by at least 50%. This is a bit in contrast to Rasmus Lerdorf's "Simple is Hard" talk at Froscon 2008 I have listened: he reported about a smaller difference.
To compare the framework overhead against plain PHP, the performance of delivering the PHP file was used as reference and set to 100%.
The overhead for tk_self reduces the performance down to 34%, but is still about 6 times as fast as CodeIgniter; this may be because tk_self has very few code to parse.
But this is also an argument why one shouldn't take these results too serious: web-applications will spend most of their time by running loops, waiting for data from databases and may be more worse things. This will take much more time than the 2.0 resp. 11.9 milliseconds mentioned above. So it's mainly up to you to keep your web applications fast.