Troubleshooting Nginx Upstream Timed Out (110: Connection Timed Out) in PHP-FPM and WordPress: Production Diagnostic Runbook

Resolve Nginx upstream timed out 110 errors and 504 Gateway Timeouts in WordPress and PHP-FPM. Tune fastcgi_read_timeout, pm.max_children, and slow query logs.

Troubleshooting Nginx Upstream Timed Out (110: Connection Timed Out) in PHP-FPM and WordPress: Production Diagnostic Runbook
Direct Command Fix

To fix Nginx upstream timed out (110: Connection timed out) in PHP-FPM and WordPress: Increase fastcgi_read_timeout 300s; inside your Nginx server block, synchronize request_terminate_timeout = 300s in PHP-FPM's www.conf, raise max_execution_time = 300 in php.ini, and reload both daemons using systemctl reload nginx php8.x-fpm.[1]

Follow this production runbook to synchronize FastCGI timeouts, trace stalled PHP worker executions via the slow log, and optimize database concurrency under heavy WooCommerce traffic.[2]


Anatomy of the Upstream Timed Out (110: Connection Timed Out) Error

When Nginx acts as a reverse proxy or FastCGI gateway in front of PHP-FPM, it hands off incoming HTTP requests to PHP worker processes over a Unix domain socket or local TCP port (such as 127.0.0.1:9000). By default, Nginx enforces a strict 60-second limit on how long it will wait for the upstream backend to compile the script, query MySQL/MariaDB, and return the HTTP response headers.[1]

If a WordPress request exceeds 60 seconds without returning headers, Nginx aborts the connection, writes the error to /var/log/nginx/error.log, and serves an HTTP 504 Gateway Time-out to the client browser:[3]

2026/11/22 10:14:02 [error] 48210#48210: *184920 upstream timed out (110: Connection timed out) 
while reading response header from upstream, client: 192.0.2.45, server: example.com, 
request: "POST /wp-admin/admin-ajax.php HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", 
host: "example.com", referrer: "https://example.com/wp-admin/edit.php?post_type=shop_order"

For high-traffic e-commerce operations in South Asia, running resource-intensive WooCommerce checkouts or ERP data synchronizations on bare-metal hardware like NextGen Pakistan Dedicated Servers ensures that low-level CPU throttling and storage I/O stalls never compound upstream FastCGI latency.


FastCGI & PHP-FPM Timeout Synchronization Matrix

The following configuration matrix details default settings, recommended production values, and file locations required to prevent upstream 110 connection timeouts:[1], [4]

Parameter Directive Default Value Recommended High-Load Value Configuration File Path Operational Impact
fastcgi_read_timeout 60s 180s - 300s /etc/nginx/conf.d/*.conf Maximum duration Nginx waits for FastCGI response headers
fastcgi_send_timeout 60s 180s - 300s /etc/nginx/conf.d/*.conf Maximum duration Nginx waits to transmit request data to PHP-FPM
fastcgi_connect_timeout 60s 60s /etc/nginx/conf.d/*.conf Timeout for establishing the initial socket connection to PHP
request_terminate_timeout 0 (disabled) 180s - 300s /etc/php/8.x/fpm/pool.d/www.conf Hard timeout where PHP-FPM terminates a stalled worker thread
max_execution_time 30 180 - 300 /etc/php/8.x/fpm/php.ini Maximum script execution duration enforced by PHP runtime engine
max_input_time 60 180 - 300 /etc/php/8.x/fpm/php.ini Maximum time PHP allows for parsing POST/GET payload inputs
listen.backlog 511 2048 - 4096 /etc/php/8.x/fpm/pool.d/www.conf Queue depth for pending socket handshakes under sudden traffic spikes

What Causes “Upstream Timed Out (110: Connection Timed Out)” in Nginx with PHP-FPM?

The error stems from one of four primary server-level bottlenecks:[2]

  1. Long-Running Database Queries: In WordPress, unindexed queries on large tables (such as wp_postmeta, wp_options autoloaded records, or WooCommerce order logs) block the PHP worker from proceeding until MySQL finishes scanning disk tables.
  2. Synchronous Third-Party HTTP Calls: Plugins making synchronous cURL calls to external payment gateways, licensing servers, or webhook endpoints will hang if the remote server takes longer than the Nginx timeout threshold.
  3. PHP-FPM Worker Pool Starvation: When concurrent user requests exceed the configured pm.max_children pool limit, new requests are held in the socket backlog queue. If existing workers do not finish within the backlog timeout, waiting requests fail with error 110.[4]
  4. Asymmetric Timeout Configurations: Configuring a high timeout in Nginx while leaving PHP-FPM or php.ini at 30–60 seconds leads to unpredictable 502 Bad Gateway or 504 Gateway Timeout responses depending on which daemon aborts first.
Pro Tip on Profiling Slow Scripts: Never blindly increase timeouts to 600 seconds without enabling the PHP-FPM slow log. Configuring request_slowlog_timeout = 5s automatically records the full PHP call stack and file line numbers for any transaction that exceeds 5 seconds, exposing runaway plugins without masking architectural flaws.

How Do I Increase fastcgi_read_timeout in Nginx to Stop 504 Gateway Timeouts?

To extend the timeout window in Nginx, edit your site’s virtual host configuration file (typically located at /etc/nginx/sites-available/your-domain.conf or /etc/nginx/conf.d/default.conf):[1]

Locate your PHP processing block (usually location ~ \.php$) and declare the FastCGI timeout directives:

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

    # Extend FastCGI timeouts to 300 seconds
    fastcgi_connect_timeout 60s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;

    # Optimize FastCGI buffer allocations
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

Validate your Nginx configuration syntax and reload the service:

sudo nginx -t
sudo systemctl reload nginx

If your architecture utilizes an upstream proxy layer (such as Nginx reverse proxying to an Apache backend), replace the FastCGI directives with proxy equivalents: proxy_connect_timeout 60s;, proxy_send_timeout 300s;, and proxy_read_timeout 300s;.[1]


Why Does PHP-FPM Still Terminate After Increasing fastcgi_read_timeout in Nginx?

Increasing fastcgi_read_timeout solely instructs Nginx to wait longer for upstream headers. If PHP-FPM itself kills the worker before Nginx reaches its timeout, the connection drops prematurely.[4]

To ensure complete synchronization across the application stack:

Step 1: Update PHP Runtime Execution Limits

Edit your active php.ini file (e.g., /etc/php/8.3/fpm/php.ini):

max_execution_time = 300
max_input_time = 300
memory_limit = 512M

Step 2: Configure Worker Pool Termination Limits

Edit your PHP-FPM pool configuration file (e.g., /etc/php/8.3/fpm/pool.d/www.conf):

request_terminate_timeout = 300s

Step 3: Restart PHP-FPM

Restart the specific PHP-FPM daemon to apply pool changes:

sudo systemctl restart php8.3-fpm
Common Pitfall: Setting request_terminate_timeout = 0 disables PHP-FPM's hard kill mechanism entirely. While this prevents premature termination, a single infinite loop or stuck database lock will permanently consume that worker thread, eventually draining all available processes and freezing the entire web server.

How Do You Identify Which WordPress Plugin or Slow Query Is Blocking PHP Workers?

To identify the root cause behind prolonged script execution, activate the native PHP-FPM slow log:[4]

Step 1: Enable the Slow Log in www.conf

Open /etc/php/8.3/fpm/pool.d/www.conf and configure the logging directives:

slowlog = /var/log/php-fpm/www-slow.log
request_slowlog_timeout = 5s
request_slowlog_trace_depth = 20

Restart PHP-FPM, then monitor the log file in real time:

sudo tail -f /var/log/php-fpm/www-slow.log

The resulting log output displays the exact stack trace, function call, and WordPress file triggering the delay:

[22-Nov-2026 10:28:14]  [pool www] pid 51042
script_filename = /var/www/html/wp-admin/admin-ajax.php
[0x00007f3a8b214a10] curl_exec() /var/www/html/wp-content/plugins/custom-gateway/gateway.php:142
[0x00007f3a8b214950] send_payload() /var/www/html/wp-content/plugins/custom-gateway/gateway.php:89
[0x00007f3a8b214840] process_order() /var/www/html/wp-includes/class-wp-hook.php:324

Step 2: Inspect MySQL Slow Queries

Enable MySQL’s slow query log to identify unindexed database calls:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 2;
SET GLOBAL log_queries_not_using_indexes = 'ON';

Inspect /var/log/mysql/mysql-slow.log using mysqldumpslow to find queries causing FastCGI workers to wait on table locks.[5]

For enterprises scaling large multi-tenant WooCommerce stores or high-concurrency SaaS applications, moving from shared hypervisors to isolated bare-metal compute like NextGen Global Dedicated Servers eliminates IOPS contention and hypervisor steal time during peak database operations.


How to Calculate Optimal pm.max_children in PHP-FPM to Prevent Queue Timeouts?

When all PHP-FPM workers are saturated, incoming requests wait in the socket queue until fastcgi_read_timeout triggers error 110. Tuning pm.max_children prevents queue starvation while protecting system RAM from out-of-memory (OOM) kernel kills.[4]

Formula for pm.max_children

Calculate worker limits based on available memory after accounting for operating system and database requirements:

$$\text{pm.max_children} = \frac{\text{Total Available RAM} - \text{RAM Reserved for OS & MySQL}}{\text{Average PHP-FPM Process Size}}$$

Step 1: Measure Average PHP Worker Memory

Execute this terminal pipeline to calculate the average RSS memory consumed per active PHP worker:

ps --no-headers -o "rss,cmd" -C php-fpm8.3 | awk '{ sum+=$1 } END { printf ("%d MB\n", sum/NR/1024) }'

Example: On a standard WooCommerce site, average worker size typically ranges between 60 MB and 100 MB.

Step 2: Calculate Pool Capacity

On a dedicated server with 32 GB RAM where 12 GB is reserved for the OS, Nginx, and MariaDB InnoDB Buffer Pool:

  • Available RAM for PHP: $32\text{ GB} - 12\text{ GB} = 20\text{ GB} = 20,480\text{ MB}$
  • Average Process Size: $80\text{ MB}$
  • Optimal pm.max_children: $20,480 / 80 = 256$

Apply this in /etc/php/8.3/fpm/pool.d/www.conf:

pm = dynamic
pm.max_children = 256
pm.start_servers = 32
pm.min_spare_servers = 16
pm.max_spare_servers = 48
pm.max_requests = 1000
listen.backlog = 2048

Setting pm.max_requests = 1000 forces worker processes to recycle after handling 1,000 requests, mitigating PHP memory leaks in legacy plugins.[4]


Step-by-Step Production Checklist & Diagnostic Runbook

Execute this verification sequence when deploying timeout adjustments on production web clusters:

  1. Check Nginx Error Logs: Identify the exact virtual host and URI generating error 110:
    grep -E "upstream timed out|504" /var/log/nginx/error.log | tail -n 20
  2. Review System Load & Memory: Check if server CPU load or swap usage is elevating execution time:
    top -b -n 1 | head -n 15
    free -m
  3. Synchronize Timeouts: Align fastcgi_read_timeout 300s; in Nginx with request_terminate_timeout = 300s and max_execution_time = 300.
  4. Tune Socket Backlog Depth: Ensure the Linux kernel socket backlog accommodates high concurrency:
    sudo sysctl -w net.core.somaxconn=4096
    echo "net.core.somaxconn = 4096" >> /etc/sysctl.conf
  5. Reload Services Cleanly: Validate configurations before performing seamless daemon reloads:
    nginx -t && php-fpm8.3 -t
    systemctl reload nginx
    systemctl reload php8.3-fpm
  6. Verify Active Pool Status: Check the PHP-FPM status page (/fpm-status) to monitor active processes, idle workers, and listen queue depth under live load.

Accelerate Your High-Traffic WordPress & WooCommerce Platforms

Eliminate PHP-FPM worker starvation, achieve sub-200ms TTFB, and maintain 99.99% uptime with NextGen.pk. Deploy dedicated bare-metal servers with ultra-fast NVMe storage, dedicated gigabit uplinks, and enterprise hardware located right here in Pakistan.

Deploy Pakistan Dedicated Servers   Explore Global Bare-Metal

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute professional server engineering advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content. Test all configuration directives in a staging environment prior to production deployment.

Sources & Official References
  1. NGINX Documentation - Module ngx_http_fastcgi_module (fastcgi_read_timeout)
  2. WordPress Developer Handbook - Server Optimization & Database Performance
  3. RFC 9110 - HTTP Semantics: Status Code 504 (Gateway Timeout)
  4. PHP Manual - FastCGI Process Manager (FPM) Configuration Directives
  5. MySQL 8.0 Reference Manual - The Slow Query Log & Performance Schema

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.