You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Range of idle workers kept warm. For Nextcloud, keep ``pm.min_spare_servers``
195
+
high enough to absorb a sync-client burst without spawning new processes::
196
+
197
+
pm.min_spare_servers = 4 # adjust upward for many connected clients
198
+
pm.max_spare_servers = 16
199
+
200
+
``pm.max_requests``
201
+
Recycle a worker after this many requests. ``0`` means never recycle.
202
+
Setting a value of ``500``–``1000`` guards against slow memory growth from
203
+
leaky extensions (Imagick, LDAP, SAML XML parsers). Essential under ``static``
204
+
mode.
205
+
206
+
``pm.process_idle_timeout`` *(ondemand only)*
207
+
How long an idle worker lives before being killed. Default: ``10s``.
208
+
209
+
Example configuration
210
+
^^^^^^^^^^^^^^^^^^^^^
211
+
212
+
A starting point for ``dynamic`` mode on a server with 2 GB of RAM dedicated to PHP
213
+
(adjust ``pm.max_children`` based on your measured worker RSS):
214
+
215
+
.. code-block:: ini
216
+
217
+
pm = dynamic
218
+
pm.max_children = 30
219
+
pm.start_servers = 8
220
+
pm.min_spare_servers = 4
221
+
pm.max_spare_servers = 16
222
+
pm.max_requests = 500
223
+
224
+
Use the `PHP-FPM process calculator <https://spot13.com/pmcalculator/>`_ as a
225
+
cross-check for your values.
226
+
227
+
Slow log
228
+
^^^^^^^^
229
+
230
+
Enable the slow log to identify PHP scripts that are taking too long:
231
+
232
+
.. code-block:: ini
233
+
234
+
slowlog = /var/log/php-fpm-slow.log
235
+
request_slowlog_timeout = 5s
236
+
237
+
Each entry records the full PHP backtrace of the slow request. This is the
238
+
fastest way to find the root cause of gateway timeouts and sluggish pages.
239
+
240
+
Troubleshooting
241
+
^^^^^^^^^^^^^^^
242
+
243
+
**502 Bad Gateway**
244
+
All ``pm.max_children`` workers are busy. Increase ``pm.max_children`` if RAM
245
+
allows. Enable the slow log to check whether a slow query is tying up workers.
246
+
Also check that a ``request_terminate_timeout`` is not killing workers mid-request.
247
+
248
+
**504 Gateway Timeout**
249
+
A worker is running but not responding within the web server's upstream timeout
250
+
(nginx ``fastcgi_read_timeout``, Apache ``ProxyTimeout``). Common Nextcloud causes:
251
+
large file operations, slow database queries during sync, or PROPFIND over large
252
+
directory trees. Use the slow log to identify the bottleneck.
253
+
254
+
**Memory grows over time**
255
+
Memory leaks can occur in worker processes. Common culprits include libraries that manage external resources (like Imagick for image processing). Use the slow log and RSS monitoring to identify which requests cause growth.
256
+
Set ``pm.max_requests = 500`` to recycle them before they grow too large.
257
+
258
+
**Slow first request after idle**
259
+
``pm = ondemand`` or ``pm.min_spare_servers`` too low. Switch to ``pm = dynamic``
260
+
and raise ``pm.min_spare_servers``.
261
+
262
+
After any configuration change, reload PHP-FPM — changes do not take effect until you do:
263
+
264
+
.. code-block:: bash
265
+
266
+
sudo systemctl reload php8.3-fpm # Debian/Ubuntu — adjust version as needed
267
+
sudo systemctl reload php-fpm # RHEL/Fedora
268
+
269
+
For pool configuration details (environment variables, upload sizes, Unix socket vs TCP),
270
+
see :ref:`php_fpm_tips_label` in the installation guide.
0 commit comments