Abstract Fonts has been running on Apache/mod_php clustered setup for many years now but recently we've encountered performance issues stemming from apache/mod_php using too much memory.

In the picture you can see that apps consumed most of the memory on this particular web server. That happens due to mod_php being loaded into each apache process and if you have hundreds of processes you will quickly run out of memory.

The worst part is that even static files are served by processes that have mod_php loaded in. This is where nginx excelled by always running PHP and other processors through CGI and thus not sharing it's own memory with them, staying lean.

Enter PHP-FPM which was a breeze to install. It has a plethora of configuration options but since we are migrating from pretty simple mod_php config it was very simple to replicate. Switching half a dozen of web servers only took a couple of hours.

Our web server are running Ubuntu Server 12.04 and these are the steps we needed to execute to switch from apache2-mpm-prefork with libapache2-mod-php5

[code]sudo apt-get install apache2-mpm-worker libapache2-mod-fastcgi php5-fpm[/code]

Now, edit /etc/php5/fpm/pool/www.conf

We changed pm.num_children to be total memory divided by how much a php-fpm process takes up (about 70-80MB in our case)

We also uncommented pm.max_requests and set it to 1000, to make sure workers get restarted to avoid memory leaks in 3rd party modules.

We changed pm.listen to /tmp/php5-fpm.sock to list on a Unix socket instead of default port 9000.

We also changed user and group from www-data to 'apache' since we had mod_php setup configure to run that way.

Because of that we had to chown the fastcgi directory to apache.apache like this:

[code]sudo chown apache.apache /var/lib/apache2/fastcgi[/code]

Now we need to configure apache to execute php scripts through fastcgi.

We had to enable 'actions' module first.

[code]a2enmod actions[/code]

Then change /etc/apache2/mods-enabled/fastcgi.conf to look something like this

[code]<IfModule mod_fastcgi.c>

AddHandler php5-fcgi .php

Action php5-fcgi /php5-fcgi

Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi

FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization

</IfModule>[/code]

Note that we are running PHP-FPM through a socket to avoid TCP/IP overhead.

[code]sudo service php5-fpm reload

sudo service apache2 restart [/code]

And you should be off to the races.

From the graph you can tell but after switching to PHP-FPM we had a huge spike in traffic (10x the usual) yet the memory usage remained extremely low, without any swapping and the system remained very responsive and unphased by the influx of visitors.

I should note that we are using PHP-FPM in conjunction with APC, but it was already installed and being used with mod_php as well.

Based on our experience PHP-FPM blows mod_php out of the water and we would HIGHLY recommend it over antiquated mod_php.

If you have had other experiences don't hesitate to share.


Looking for more fonts? Check out our New, Sans, Script, Handwriting fonts or Categories
abstract fontscontact usprivacy policyweb font generator
Processing