Skip to content

Fix WooCommerce checkout 504 errors under load

WooCommerce checkout can return 504 Gateway Timeout during a sale while the rest of the store stays up. You will find which layer timed out, see what the PHP workers were waiting on, and apply the fix for that cause.

During a sale, your WooCommerce store keeps serving product and cart pages, but Place order hangs and then shows 504 Gateway Timeout. Checkout cannot be cached and it waits on your payment provider, so it is the first request to run out of PHP workers. A 504 means the web server stopped waiting for PHP. It says nothing about the order, which may have been created and paid anyway. Find which layer gave up and what the workers were waiting on, then fix that cause. A longer timeout alone makes shoppers wait longer for the same error.

Why only checkout times out

Product and category pages can come from a page cache. Checkout cannot, so every submission runs PHP from start to finish. WooCommerce validates the fields and the cart, creates the order, and then calls the selected payment gateway. That call runs inside the same request, and the shopper’s browser waits for it.

The classic (shortcode) checkout posts to /?wc-ajax=checkout. The Checkout block posts to /wp-json/wc/store/v1/checkout. Look for those two URLs in your logs.

Each request holds one PHP-FPM worker until it finishes. PHP-FPM is the service that runs PHP for the web server, and its pm.max_children setting caps how many requests run at once. When every worker is busy, new requests wait in a queue. The web server gives up on the ones that wait too long.

Several layers have their own limit, and the shortest one decides what the shopper sees.

LayerSettingDefaultWhat happens when it is reached
nginx in front of PHP-FPMfastcgi_read_timeout60 snginx returns 504
nginx in front of another web serverproxy_read_timeout60 snginx returns 504
PHPmax_execution_time30 sRarely ends a checkout (see below)
PHP-FPMrequest_terminate_timeout0 (off)PHP-FPM kills the worker
CloudflareProxy Read Timeout125 sCloudflare shows Error 524

Three details in that table matter during an incident:

  • PHP’s own limit does not protect you here. On Linux, max_execution_time does not count time spent waiting on the network or the database. The classic checkout also removes the limit for its own request with set_time_limit( 0 ).
  • The nginx timer is a silence timer. It runs out when PHP sends nothing for 60 seconds, which includes time spent waiting in the queue for a free worker.
  • Cloudflare passes your 504 through. A Cloudflare-branded 504 page means your own server returned the 504. Cloudflare’s own timeout shows as Error 524. For that one, see Cloudflare error 524.

On Apache with mod_proxy_fcgi, the matching setting is ProxyTimeout. It defaults to the value of Timeout.

Step 1: Check the orders before anything else

The web server gave up, but the PHP worker may have carried on. An order can exist, and the card can be charged, behind a 504 page. Shoppers who retry may pay twice.

List recent orders by status. Replace 1 with the ID of an administrator user.

wp wc shop_order list --status=pending --per_page=10 --user=1
wp wc shop_order list --status=failed --per_page=10 --user=1

Compare what you see with the payments in your gateway’s dashboard. Most gateways also confirm payment through a webhook, a request the gateway sends to your store when the payment succeeds. A working webhook marks the order as paid even when the shopper’s browser saw a 504. If paid orders stay on Pending payment, fix that first with orders stuck on Pending payment.

Step 2: Confirm which layer returned the 504

On an nginx server, search the error log for upstream timeouts.

grep "upstream timed out" /var/log/nginx/error.log | tail -20

Example output:

2026/11/20 09:07:42 [error] 1412#1412: *88317 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 203.0.113.24, server: example.com, request: "POST /?wc-ajax=checkout HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "example.com"

Lines like this for the checkout URLs confirm that nginx waited 60 seconds on PHP. If the log has no such lines, the 504 came from a layer in front of this server, such as a load balancer. Check that layer’s log instead.

Step 3: See whether the PHP workers ran out

Search the PHP-FPM log for the warning it writes when the pool is full. The path below is the Debian and Ubuntu one for PHP 8.3. On AlmaLinux and Rocky Linux, the file is /var/log/php-fpm/error.log.

grep "max_children" /var/log/php8.3-fpm.log | tail -5

Example output:

[20-Nov-2026 09:04:17] WARNING: [pool www] server reached pm.max_children setting (12), consider raising it

If the pool has a status page (pm.status_path is set and reachable locally), it shows the queue live. Replace /fpm-status with your own path.

curl -s 'http://127.0.0.1/fpm-status'

Example output:

pool:                 www
process manager:      dynamic
start time:           20/Nov/2026:06:12:44 -0500
start since:          10497
accepted conn:        48213
listen queue:         37
max listen queue:     112
listen queue len:     511
idle processes:       0
active processes:     12
total processes:      12
max active processes: 12
max children reached: 9
slow requests:        164

idle processes: 0 with a listen queue above zero means requests are waiting for a worker. That is the saturation behind the 504.

Step 4: See what the workers are waiting on

A full pool is the symptom. The cause is whatever keeps each worker busy for so long. The PHP-FPM slow log answers that: it records a stack trace for every request that runs longer than a threshold you set.

Add these two lines to the pool file. On Debian and Ubuntu that is /etc/php/8.3/fpm/pool.d/www.conf, and on AlmaLinux and Rocky Linux it is /etc/php-fpm.d/www.conf.

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

Test the configuration, then reload the service. The names below are the Debian and Ubuntu ones. Use php-fpm for both on AlmaLinux and Rocky Linux.

sudo php-fpm8.3 -t
sudo systemctl reload php8.3-fpm

Read the top line of each trace. It names the function the worker was stuck in.

tail -n 40 /var/log/php-fpm-slow.log

Example output:

[20-Nov-2026 09:05:31]  [pool www] pid 21877
script_filename = /var/www/example.com/public/index.php
[0x00007f6a3be14f40] curl_exec() /var/www/example.com/public/wp-includes/Requests/src/Transport/Curl.php:205
[0x00007f6a3be14e80] request() /var/www/example.com/public/wp-includes/Requests/src/Requests.php:469
[0x00007f6a3be14d50] request() /var/www/example.com/public/wp-includes/class-wp-http.php:413
  • curl_exec() at the top means the worker is waiting on another company’s server. Read further down the trace for the plugin folder that made the call. It is either the payment gateway or another plugin that calls out during checkout.
  • mysqli_query() at the top means the worker is waiting on the database. Look at what the database is doing right now:
wp db query "SHOW FULL PROCESSLIST"
wp db query "SHOW ENGINE INNODB STATUS\G" | grep -A 5 "LATEST DETECTED DEADLOCK\|LOCK WAIT"

Many rows running the same statement, each with a Time of several seconds, point to lock contention or a slow query.

Gateway plugins also write their own logs when logging is turned on in their settings. Read them in WooCommerce > Status > Logs. With the default file storage they are in wp-content/uploads/wc-logs/.

Fix the cause you found

The payment gateway is slow. Open the provider’s status page. If the provider is degraded, more workers will not help, because each one waits just as long. Gateway plugins can wait longer than nginx does. The WooCommerce Stripe plugin, for example, sets a 70-second timeout on its API calls. Tell shoppers what is happening before they retry. You can also turn on an offline method such as Direct bank transfer in WooCommerce > Settings > Payments until the provider recovers.

Another plugin calls out during checkout. Abandoned-cart trackers, marketing automation, ERP sync and fraud screening often run on the woocommerce_checkout_order_processed hook. The Checkout block fires woocommerce_store_api_checkout_order_processed instead. Anything attached to those hooks runs before the shopper gets a response. Look in the plugin’s settings for a background or queue option, or deactivate the plugin for the length of the sale.

If the slow call is in your own code, queue it with Action Scheduler, the background job runner that ships with WooCommerce. Checkout then only records the job:

add_action( 'woocommerce_checkout_order_processed', function ( $order_id ) {
    as_enqueue_async_action( 'myshop_sync_order', array( $order_id ), 'myshop' );
} );
add_action( 'myshop_sync_order', 'myshop_send_order_to_crm' );

Here myshop_send_order_to_crm stands for your own function. Queued jobs still have to run, so keep an eye on the queue with the Action Scheduler backlog guide.

The pool is too small for the traffic. Measure what one worker uses before you raise the limit.

ps -eo rss,cmd --no-headers | awk '/php-fpm: pool/ {sum+=$1; n++} END {if (n>0) print n, sum/n/1024 " MiB avg"}'

Example output:

12 118.4 MiB avg

Divide the memory you can give to PHP by that figure. Leave out what the database, the web server and the system need. With 2,440 MiB for PHP and 120 MiB per worker, the limit is 20.

pm.max_children = 20

Test and reload PHP-FPM as in Step 4. A limit set too high makes the server run out of memory, which is worse than a queue. PHP-FPM pool sizing covers the measurement in detail.

Other requests are using the workers. The cart-fragments script requests /?wc-ajax=get_refreshed_fragments to refresh the mini-cart. That request cannot be cached, so each one takes a worker. Since WooCommerce 7.8, the script loads only when the Cart widget is on the page, but themes and plugins can still load it everywhere. Count those requests in your access log. If they are heavy, follow the cart fragments guide.

The database is the wait. WooCommerce keeps cart sessions in its own table, wp_woocommerce_sessions with the default prefix. It reads them through the object cache first. A persistent object cache such as Redis takes those reads, and many other repeated lookups, off the database. WooCommerce still writes each session to the table.

Also check the options WordPress loads on every request. Since WordPress 6.6, Tools > Site Health warns when autoloaded options pass 800,000 bytes. The autoload audit shows how to find the large ones.

Prove it is fixed

Do not wait for the next sale to find out. Run a load test against a staging copy with k6 for WooCommerce checkout. While it runs, check three things:

  • The grep "upstream timed out" command from Step 2 shows no new lines.
  • max children reached on the status page stops rising, and listen queue returns to 0.
  • The slow log gets no new checkout traces.

When this is the wrong approach

These steps are for a checkout that fails only when many people buy at once. If checkout is slow with a single shopper, the cause is in the request itself. Use WooCommerce slow checkout for that. If every page returns 504, start with WordPress 504 Gateway Timeout.

Raising fastcgi_read_timeout is rarely the answer for checkout. Each slow request then holds its worker even longer. If you do need to change it, nginx 504 timeout tuning explains which timeout applies where.

Official references: the nginx fastcgi module documentation and the PHP manual’s FPM configuration page.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.