Your PHP import returns a 504 error after about a minute, even though you max_execution_time Have you set it higher? At first, the status simply indicates that a gateway did not receive the required response in time. The import can still continue. First, check which process generated the 504 error, and compare the time of the error with the PHP-FPM and application logs. This will help you determine whether the connection was simply closed or whether PHP or PHP-FPM terminated processing.
What a 504 Actually Means
Your PHP import doesn't return any visible response for about a minute. Then „504 Gateway Timeout“ appears, even though you max_execution_time set higher. This isn't a contradiction: The status means that a Gateway did not receive the required response from its upstream in time. The status alone does not indicate whether PHP is still running at this point, has already finished, or has been terminated.
So start by drawing the actual Inquiry Process For the import URL: The browser may first reach a CDN or a load balancer, then the web server, and finally the relevant FPM pool via the web server’s PHP connection. The PHP code, in turn, may be waiting for a response from a database or an external API. These services are not directly in the browser’s HTTP path, but they can cause delays in the web server receiving response data.
With fastcgi_pass nginx forwards the request via FastCGI to, for example, PHP-FPM. With proxy_pass An Nginx server, on the other hand, forwards requests to its backend via HTTP or HTTPS. Apache HTTP Server 2.4 can handle requests via ProxyPass or pass it on to a proxy handler. Check the destination and protocol for each intermediate step. An HTTP proxy may be located in front of the web server, which in turn communicates with PHP-FPM via FastCGI. If the upstream proxy generates the 504 error, first investigate its connection to the web server, not the FastCGI connection behind it.
The duration of approximately one minute provides a search range for the diagnosis. It does not correspond to a specific nginx directive or a PHP timeout. The key factor remains which connection and which phase the waiting period expired in.
How much time PHP actually counts
max_execution_time limits the PHP Script Timer Recorded execution time. If PHP reaches this limit, normal script execution is terminated with a fatal error. If you find the message „Maximum execution time … exceeded“ in the PHP log for the request in question, this is concrete evidence that the script timer has been triggered. Allowing the web server more time will not prevent this error.
A successful call to set_time_limit(30) resets the timer. If PHP has already tracked 20 seconds by that point, 30 tracked seconds will be available again starting from the call, rather than just the 10 seconds that would remain from an original 30-second limit. Without any further changes, the timer in this example could therefore trigger after a total of 50 recorded seconds. The function call does not reset a gateway’s timeout.
What constitutes a recorded second depends on the PHP environment. With standard CPU time measurement on non-Windows systems, wait times for streams or database queries may fall outside the recorded time. If an import waits a long time for a query, significantly more time may elapse for the browser than PHP counts toward its limit. On Windows, however, PHP counts the elapsed time.
Is PHP compatible with --enable-zend-max-execution-timers Once compiled, the timer measures elapsed time, including I/O wait time. For diagnostic purposes, what matters is whether the option is enabled in the actual build of the web environment being used. A CLI call may use a different PHP installation or configuration and does not reflect the actual value of the web request.
When importing data into WordPress, it's worth taking a look at the process yourself. The post on Common WordPress issues, such as resource-intensive plugin imports and slow queries is used here solely to identify the cause. The primary sources cited in this article and the current settings in your environment are decisive for the effect and calculation of the time limits.
When PHP-FPM Terminates the Worker
PHP-FPM has request_terminate_timeout a separate limit on how long a worker can process a request. The documented default value is 0 the limit is disabled. If it is enabled and is exceeded, FPM terminates the Worker Process. This does not necessarily result in a PHP fatal error due to the maximum script execution time: The script timer may still have time remaining, for example during a wait phase that it does not count toward the limit in this build.
A worker termination is not an orderly application shutdown. This can cause an import to end before it saves its completion status, even though previous write operations have already been completed. If you suspect this, search the FPM log for a message regarding the affected worker and compare it with the application log. When doing so, check the configuration of the pool that processed the request, not that of another pool on the same server.
According to the PHP-FPM documentation, request_terminate_timeout to fastcgi_finish_request() and is not applied during an internal shutdown if request_terminate_timeout_track_finished is disabled. Its documented default is no. If it is enabled and request_terminate_timeout If set to "positive," the existing processing time limit continues to apply during these phases; it does not restart upon completion of the response or shutdown. This description refers to the documented settings. Neither a worker termination nor the safe continuation of the import can be inferred from the browser response alone.
If you want to start by figuring out where a slow request is getting stuck, request_slowlog_timeout the appropriate FPM setting. Once this threshold is exceeded, FPM can generate a PHP backtrace in the Slowlog record; this does not guarantee a usable trace in every case. The call stack may show that PHP was, for example, in the middle of a database call at the time of recording. It does not yet explain why that call was slow. The slowlog threshold itself does not terminate the worker.
A Comparison of PHP and Web Server Timeouts
A PHP timeout and a web server timeout can both affect the same import, but they do not limit the same phase. The decisive factor is the Sequence of events leading to the demolition: Does PHP terminate the script, does FPM terminate the worker, or does nginx close the connection? Only then can you determine which setting you should check and which change won't solve the problem.
| shift | directive | What is being measured? | What is coming to an end? | Where should you look first? |
|---|---|---|---|---|
| PHP | max_execution_time | Script execution tracked by the PHP timer; measurement method depends on the platform and build | Script Execution with a Fatal Error | PHP error log and the actual PHP value of the web request |
| PHP-FPM | request_terminate_timeout | Processing time for a request in the worker; 0 disables the limit. Documented exception after the response is complete and during shutdown when `request_terminate_timeout_track_finished = no` (documented default for this option). Enabled: An existing positive timeout period remains in effect and does not restart from that point. | FPM terminates the worker process | FPM Log and Configuration of the Relevant Pool |
| nginx → FastCGI | fastcgi_read_timeout | Pause between read operations when receiving the FastCGI response | nginx closes the FastCGI connection | nginx error log and configuration of the affected route |
| nginx → HTTP upstream | proxy_read_timeout | Pause between read operations when receiving the HTTP upstream response | nginx closes the upstream connection | nginx error log and proxy configuration for the affected route |
| Apache 2.4 → Proxy Backend | Worker timeout; otherwise, ProxyTimeout, and if neither is specified, TimeOut | Socket wait time for data to or from the backend | Data exchange may fail due to a socket timeout; this does not necessarily indicate a PHP error | The appropriate proxy worker and a valid Apache configuration |
| Client → nginx | client_body_timeout | Pause between read operations when receiving the request body | nginx returns a 408 status code for the request | nginx logs and configuration of the affected path |
The FastCGI and HTTP lines refer to different nginx connections. For both, nginx documents a limit on read operations, not the total response time. In Apache, it describes timeout On the other hand, set the socket timeout on the relevant proxy worker. Its default value is ProxyTimeout; if that isn't set either, then TimeOut. Do not apply the nginx idle timeout rule to Apache without first verifying it. First, determine which worker is actually responsible and its effective setting.
Do not confuse waiting for a response to a current request with waiting for the next request over an already open client connection. The Guide to Apache KeepAliveTimeout explains the second case. For the 504 diagnosis, however, the decisive factor is which instance was waiting for a response from its upstream.
Why 20 seconds Is Not the Total Duration
Illustrative calculation example; not a measurement. Suppose nginx passes a request to PHP-FPM via FastCGI, and the following directive applies to the relevant nginx path. It limits the Reading Break upon receiving the FastCGI response. The 20 seconds are only intended to illustrate the effect of this setting; they are not a recommended value for production.
The request has already been passed to FastCGI. If PHP-FPM were to deliver the first response byte only after 25 seconds, the read timeout would have expired by then: nginx can close the FastCGI connection even though the PHP timer has not yet triggered. If, on the other hand, nginx receives complete response headers and then data at regular intervals of less than 20 seconds, the response can take significantly longer overall without violating this limit.
A echo The PHP code does not track when Nginx has read the response data. Conversely, Nginx can buffer the FastCGI response, so data may already have arrived there even though nothing is yet visible in the browser. This limit is determined by when the data is received by Nginx, not by the first visible output in the browser. If nginx has already sent the final response status to its client, it can no longer replace it with a 504 in the event of a subsequent read timeout. The response may remain incomplete; therefore, do not search the access log exclusively for a 504 when investigating a body abortion.
Therefore, check the error log to see which phase nginx was waiting in. For the Connection setup Regarding FastCGI: fastcgi_connect_timeout. The request is passed to FastCGI using fastcgi_send_timeout a separate limit between consecutive write operations. Only when the response is read is fastcgi_read_timeout Relevant. If the error occurs during the connection process, a longer read time does not provide any additional time for establishing the connection.
Distinguishing Between CPU Export and a Sluggish Upload
An export calculates totals for thousands of records and formats them for a file. For this exact request, the PHP log of the Fatal Error „Maximum execution time … exceeded,“ the PHP script timer reported. Increasing the nginx timeout doesn't change anything: nginx might wait longer for a response, but that won't cause the terminated script to continue running.
When exporting, first determine which processing step takes the most time. If, for example, the same totals are recalculated for each row, it’s worth consolidating this work. If the volume cannot be reduced, divide it into manageable work packages. A targeted increase in the PHP limit is more appropriate for a known, manageable export than for a process whose duration varies greatly depending on the amount of data.
When the upload is stalled, the direction is reversed: nginx is still waiting for data from the client, not on a response from PHP. If no further data arrives for too long while reading the request body, then client_body_timeout trigger. nginx then terminates the request with an HTTP 408 error, possibly before any PHP application code even runs. A slow transfer with brief pauses in reading, on the other hand, may take longer overall than the set value.
max_input_time This relates to a different phase: The directive limits the amount of time PHP is allowed to spend parsing input data before executing the script. It does not specify how long Nginx waits for the next chunk of data during an upload. If the nginx log shows a timeout while reading the request body, you should therefore make a change to max_input_time in the wrong place. Neither of these limits is a general time limit for the entire upload duration.
Find the trigger in the logs
For a specific failed import, record the time (including the time zone), the route, the HTTP status, and, if available, the Request ID. Search for the same event in the logs of the CDN, load balancer, and web server to identify which instance reported the issue first and determine the phase in which the error occurred.
If the answer is a Proxy-Status-If the header contains this information, it can provide a clue about the intermediate server involved and its error. If nginx triggered the timeout, search the error log for the Error Phase: Did the connection to the upstream server fail, or did the request fail to send, or did the response fail to load? A timeout during connection establishment is not the same as a read timeout. During the read phase, nginx may first wait for the response header and later for additional data from the response body.
Cross-reference the time of the error with the FPM and application logs. A message about a terminated worker provides different information than a PHP fatal error or an application log that reports additional records processed after the 504 error. If there is no common ID, timestamps and the route can help with assignment. However, when multiple imports are running simultaneously on the same route, they are not always sufficient to uniquely identify a log entry.
Are the following already in the nginx access log: $upstream_connect_time and $upstream_response_time If available, use these timestamps to correlate the same operation with the error, FPM, and application logs. Identify the error phase based on the error log message, rather than inferring it from a single timestamp. Upstream times alone do not indicate whether PHP is performing calculations, waiting for a database response, or has not even begun processing yet.
Only then should you check the applicable settings for the route in question. For nginx, use fastcgi_pass is for missing FastCGI response data fastcgi_read_timeout relevant; in the case of proxy_pass and an HTTP backend proxy_read_timeout. In the Apache proxy, check the timeout of the responsible worker as well as the guidelines ProxyTimeout and TimeOut. Compare the connection in question with the logged error phase. Do not change the FastCGI limit of a downstream server if an upstream proxy connection is affected.
If an FPM session times out, check the relevant pool. Determine the PHP value in the context of the web request, since the CLI may load a different configuration. A timeout after approximately 60 seconds is a clue, but not proof of a specific default value.
Identifying Queues and Slow Dependencies
If the 504 errors occur primarily during parallel imports or during peak times, check the FPM Queue. The FPM status page shows listen queue, how many requests are currently waiting for an available process. Compare this value with the number of active and available processes. A growing queue combined with a shortage of available workers suggests that some of the wait time occurs even before the application code is executed.
Compare the status values with the error timestamps. Checking the pool after the peak load has ended may reveal an empty queue. Conversely, a value other than zero at max children reached It's just that the pool has already reached its process limit since it started—not that this happened during the import being investigated. Restrict access to the status page to authorized internal users; it does not belong on the public network.
The queue indicates the bottleneck, but it does not yet explain why the workers are busy. The FPM Slowlog You can use a backtrace to see exactly where PHP is in the process when a request is slow. If entries are piling up during a database or API call, check the duration of those calls in the application logs or with the respective service. A backtrace alone does not show how long an individual call has been waiting, nor why the remote server is responding slowly.
If a dependency is blocking the import, set a specific time limit there whenever possible—for example, for establishing a connection to the API and for the entire transfer, or for executing a database query, provided the driver or database supports it. Allow enough time for the application to handle and report the error before the gateway times out. However, increasing the nginx read timeout does not free up workers; it may simply cause requests to wait longer in the same overloaded pool.
Will the import continue after the 504?
You can check whether the import is still in progress by looking at its Technical Order Status. The HTTP status alone does not indicate which changes have already been saved or rolled back.
In nginx, there are two possible scenarios: either the client terminates the connection before receiving a response, or nginx reaches its own fastcgi_read_timeout. fastcgi_ignore_client_abort applies only to the first case; nginx’s client can also be an upstream proxy. The default value off If a client disconnect is detected, this may cause the FastCGI connection to close; this is not guaranteed for every configuration.
The setting on Ignore it. The directive does not prevent a FastCGI read timeout and does not keep the connection open when it expires. Separately, PHP's ignore_user_abort an error detected by PHP; PHP can only detect it when it actually attempts to output data. None of these settings guarantees that the process will continue: the PHP runtime limit, the FPM limit, and the application itself can still terminate the import.
Before resubmitting, check the business status, not just the HTTP status. If the application has assigned an import ID, look for it in the import log or in the status view. For an import that saves records in batches, some of the data may have already been processed. If the job is still running or its status is unclear, restarting it may cause the same data to be processed again.
You can specifically limit short tasks with a predictable duration or break them down into smaller chunks with saved progress. For long or highly variable tasks, a Background Job More appropriate: The web request submits the job and returns an ID that can be used to retrieve its status. Design the process for repeated requests so that the same job ID does not trigger a second import and so that a restart does not process already-saved packages twice.
fastcgi_finish_request() This does not replace the job queue. If successful, the function completes the response from PHP-FPM’s perspective and allows the script to continue running afterward. The end of the response and the end of the script are thus separated. In the audited FPM code from PHP 8.4.1, the same worker remains occupied as long as the script continues to run. The code does not accept the next request until after the script has finished executing and the request has been shut down. Downstream buffering can affect when data reaches the browser; nginx can buffer FastCGI responses. Therefore, the import status is determined by the actual completion of the application, not solely by the HTTP response sent.
Sources and Current State of Knowledge
Status of the research:
Status of research for this project: November 20, 2026. Time limits are considered separately for PHP/PHP-FPM, nginx with FastCGI or HTTP upstream, and Apache HTTP Server 2.4 mod_proxy. The actual loaded configuration and the version in use are decisive. No measurements were performed on production systems.
https://www.rfc-editor.org/rfc/rfc9110.pdf
https://www.php.net/connection-handling
https://www.php.net/manual/en/function.set-time-limit.php
https://www.php.net/manual/en/install.fpm.configuration.php
https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html
https://nginx.org/en/docs/http/ngx_http_proxy_module.html
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html
https://www.php.net/manual/en/info.configuration.php
https://nginx.org/en/docs/http/ngx_http_core_module.html
https://www.rfc-editor.org/rfc/rfc9209.html
https://blog.nginx.org/blog/using-nginx-logging-for-application-performance-monitoring
https://www.php.net/manual/en/fpm.status.php
https://www.php.net/manual/en/function.fastcgi-finish-request.php
https://raw.githubusercontent.com/php/php-src/php-8.4.1/sapi/fpm/fpm/fpm_main.c




