We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

PHP is everywhere and is arguably the language most widely deployed on the Internet Web.

request-response-in-php-e1542398057451

However, its not exactly known for its high-performance capabilities, especially when it comes to highly concurrent systems.

In case you know whatphp-fpmis, feel free to jump to the section on optimization.

What is PHP-fpm?

php-and-nginx

This method was calledmod_php, short for PHP as a module.

This approach had its limitations, which Nginx overcame withphp-fpm.

Inphp-fpmthe responsibility of managing PHP, processes lie with the PHP program within the server.

It is this process manager that the web server passes the requests to.

Why optimize PHP-fpm?

So why worry about all this dance when things are working all right?

Why not just leave things as they are.

Ironically, that is precisely the advice I give for most use cases.

If your setup is working fine and doesnt have extraordinary use cases, use the defaults.

Another thing to realize is that Nginx was built for handling huge workloads.

How to optimize PHP-FPM?

you could usefind commandif on UNIX.

On my Ubuntu, the path is/etc/php/7.2/fpm/php-fpm.conf.

The 7.2 is, of course, the version of PHP that Im running.

We also see that/var/log/php7.2-fpm.logis wherephp-fpmis going to store its logs.

With ten seconds on hand, theyll have a better chance of finishing their tasks and exiting gracefully.

Surprisingly, thisisntthe meat ofphp-fpmconfiguration!

In my case, the pool name turned out to bewwwand the file I wanted to edit was/etc/php/7.2/fpm/pool.d/www.conf.

Finally, we arrive at the source of the matter, the process manager (pm) setting.

Generally, youll see the defaults as something like this:

So, what does dynamic here mean?

In such cases, ondemand is a better option, letting the system decide when to launch new processes.

If you do go this route, beware that it has its guidelines and pitfalls.

A rather dense but highly useful article about it ishere.

Performance tuning is as much about guesswork and dark arts as it is system knowledge.

Even if you know all thephp-fpmsettings by heart, success isnt guaranteed.

Just keep doing what youre already doing and carry on.

At the same time, avoid the end of being a performance junkie.

), and make minor changes as needed.