Lesson 1.3: PHP-FPM pools and tuning
Under Apache or nginx the PHP-FPM pool is where a host isolates and tunes each site. This lesson covers the PHP values Exponential needs, the timeouts that must agree with each other, APCu, and the most common operational mistake: reloading a PHP-FPM master that does not serve the site.
At a glance
| Course | Hosting and operations |
| Module | Module 1: Serving the site |
| Duration | 45 minutes (20 presenting, 25 exercise) |
| Level | Intermediate |
| Audience | System administrators and hosting support staff |
| Prerequisites | Lesson 1.2; root on the learner's own virtual machine |
Learning objectives
After this lesson, learners can:
- set
memory_limit,max_execution_time, the upload limits anddate.timezonefor one pool; - explain why
request_terminate_timeoutis the real wall-clock limit under PHP-FPM; - check APCu and explain why
ApcuReservematters when sites share a master; - find the master that serves a site and preview a deploy's reload with
--dry-run.
Trainer's notes
How to present it
Source: PHP-FPM tuning and Chapter 8, PHP-FPM.
- One pool per site (3 minutes). A pool runs PHP as the site's user; it is the unit of isolation and tuning. Panels such as Plesk create one pool per domain.
- PHP values (5 minutes). Show the table of the tuning page:
memory_limitat least 256M in production,max_execution_timeat least 30 (60 in chapter 2's production example),date.timezone,file_uploads=On, upload limits for the customer's largest upload,allow_url_fopen=On,variables_ordercontainingE, emptyopen_basedir, OPcache on. The web PHP and the command-line PHP read different files. - Timeouts (4 minutes).
max_execution_timeis the script's own timer;request_terminate_timeoutis enforced by the master whatever the script does. On SQLite keepSQLiteTransactionWait(25 s by default) below the request timeout. Long jobs belong on the command line. - APCu (3 minutes). APCu is one memory for every site of the pool; when it fills up it empties itself
completely.
[QueryCacheSettings] ApcuReserve=25keeps a quarter free; keep it above 0. - Reloading (5 minutes). A reload is not confined to one site: the master waits for every child of every pool.
exp:velocity deployreloads only when it must ([DeploySettings] PhpFpmReload=auto), andPhpFpmService=autofinds the right master. Showdeploy --no-velocity --dry-run.
Common questions
How many children should a pool have? The sources give no number. They give a method: measure with
exp:benchmark --cold at rising concurrency and pick the point where p90 starts to climb (Module 7).
I changed php.ini and nothing happened. Most often the change went into the file the other PHP reads (CLI
versus FPM), or the master serving the site was not reloaded.
Why do sessions matter here? The role-aware HTTP cache needs sessions in files every server of the site can read; moved elsewhere, it stores nothing for signed-in visitors.
When must I force a reload? After a php.ini or pool change, a new PHP extension, or PHP files removed or renamed
in place (deploy --fpm-reload).
Pitfalls
- Several PHP versions. The master serving the site is often not the one called
php-fpm. Find it by its pool file, as in step 6. - Learners without root. The reload step needs root; run as anyone else it is skipped with a note. Make sure learners use their own virtual machine.
- Editing the wrong
php.ini. Have learners printphp --iniand compare with the pool'sphp_admin_valuelines.
Hands-on exercise
Use your own Linux virtual machine from lesson 1.2.
Open your site's pool file (for example below
/etc/php-fpm.d/or/etc/php/<version>/fpm/pool.d/).Note the pool's
user,listenand anyphp_admin_valuelines.Add or check these lines in the pool:
php_admin_value[memory_limit] = 256M php_admin_value[max_execution_time] = 60 php_admin_value[date.timezone] = Europe/Berlin php_admin_value[upload_max_filesize] = 64M php_admin_value[post_max_size] = 64MLook for
request_terminate_timeoutin the pool and write down its value, or that it is not set.Reload that pool's PHP-FPM service with
systemctl reload <service>.In the installation root, preview a deploy and read which master it found and whether it would reload or wait:
php bin/php/console exp:velocity deploy --no-velocity --dry-run --allow-root-userSign in to the administration of your training site and open Setup, then System information. In the section PHP extensions and settings, check
memory_limit; under OPcache and APCu, check that APCu is listed.Run
php -m | grep -i apcuand compare the command-line PHP with what the web page showed.Write down one difference between the CLI and the pool settings, if any.
Expected result
- After the reload, System information shows
memory_limit256M for the web PHP. - The
--dry-runoutput lists each deploy step asDRYand names the PHP-FPM service it found, or explains why it would skip the reload. - The learner can say whether the CLI PHP and the pool differ, and why that matters.
- The trainer checks by asking each learner which service name the dry run found.
Quiz
- Which limit is the real wall-clock limit for a request under PHP-FPM?
A.
max_execution_timeB.request_terminate_timeoutC.memory_limitD.post_max_size - What happens when a shared APCu fills up?
- Why can a PHP-FPM reload slow down other customers' sites?
- What does
[DeploySettings] PhpFpmService=autodo? - Where do long-running imports and cache warming belong, and why?
Answers
- B. The master enforces it whatever the script does (PHP-FPM tuning).
- It empties itself completely, and every other cache and counter in it is lost;
ApcuReservekeeps space free. - The master asks every child of every pool to finish its request and starts no new child until the last one has.
- It finds the master that serves the site by its pool file (Plesk, distribution and Remi naming).
- On the command line, where the PHP CLI has no execution limit by default; web timeouts stay sized for pages.
Further reading
- PHP-FPM tuning: every value and the sizing method.
- PHP settings for Exponential: the php.ini reference.
- PHP selection and FPM pools: pools in hosting panels.
- Per-customer users and pools: isolation between customers.
Related pages
- Module 1: Serving the site
- Hosting and operations: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.