Tag - symfony

This article explains how to boost the performance of a PHP site by installing a PHP accelerator software.

Why is PHP slow

PHP is an interpreted language that requires to parse the PHP files for each request received by the server.
With a compiled language such as Java or Ada, this long and error prone process is done beforehand.
Even if the PHP interpretor is optimized, this parsing step can be long. The situation is worse when
you use a framework (Symfony, CakePHP,...) that requires many PHP files to be scanned.

eAccelerator to the rescue

eAccelerator is a module that reduces this performance issue by introducing a shared cache
for the PHP pre-compiled files. The module somehow compiles the PHP files in some internal compiled
state and makes this available to the apache2 processes through a shared memory segment.

Install eAccelerator

Don't forget to copy the configuration file (have a look at its content but in most cases it works as is):

$ sudo cp eaccelerator.ini /etc/php5/conf.d/

Restart Apache server

To make the module available, you have to restart the Apache server:

$ sudo /etc/init.d/apache2 restart

Performance improvements

What performance gain can you expect... That will depend on the PHP software and the page. It's easy to
have an idea.

To measure the performance improvement, you can use the
Apache benchmarking tool. Do a performance measurement
on the web site before the installation and another one after. Be sure to benchmark the same page.

Catchable fatal error: Argument 1 passed to
sfPatternRouting::configureRoute()
must be an instance of sfRoute, string given,
called in /usr/share/php/symfony/routing/
sfPatternRouting.class.php on line 245
and defined in /usr/share/php/symfony/routing
/sfPatternRouting.class.php on line 256

It was caused by the sfGuardPlugin which was not updated correctly. I had to remove it and install it from scratch.

The goal is to keep the controller and the view as simple as possible by using the same mechanisms. Here is how in two steps.

Step 1: Provide your own sfWebRequest

First, we override the sfWebRequest to implement the missing operations and we use the setAttribute method to associate the message
with the error field. To avoid conflicts with other attributes, the error fields are prefixed with error_.