Troubleshooting guide · website-errors · Published 2026-08-16 · 3 min read
WordPress cron requests returning 502
Diagnose WordPress cron 502 bad gateway errors from PHP timeouts, web server limits, and overlapping cron runs.
- ·How cron fails
- ·Find the failing job
- ·Fix order
How WordPress cron fails with a 502
WordPress does not run a real operating-system scheduler. When someone visits the site, wp-cron.php runs at the request edges and processes events that are "due". Each visit can trigger a run of overdue jobs in that same HTTP request. That is the key fact for a 502: the visitor's request is also the cron worker, so a slow job can push the whole request past the gateway timeout (nginx timeout 60, or the PHP-FPM request_terminate_timeout), and the upstream returns 502 for the page and every cron job it tried to run.
Signs you are dealing with cron 502s
- The error log shows
wp-cron.phplines with502beside them while the front page is fine. GET /wp-cron.phpreturns 502 or a504 Gateway Timeoutwhen called manually.- A plugin reports "Scheduled event did not run" for every event due.
- The 502 appears specifically right after the double-digit second mark, which is the point the gateway timeout fires.
Because cron is fired by visitors, a site with low traffic can go for days between successful runs, then throw a pile of jobs at one unlucky request and 502 only at that moment. The failure is a schedule, not a page.
Find the failing job
- Lock the log window: add a marker to see the request edge, or view the PHP-FPM slow-log which already records requests that exceed
request.slowlog_timeout. - Check the events queue from WP-CLI:
wp cron event list --status=due --fields=hook,schedule,next_run_relative
- Identify which hooks fire at the failing time. The usual suspects are long HTTP drives inside a cron event: an external API fetch, a large email blast, an image resize loop, or a plugin health-check that calls an API endpoint per site.
- Confirm the timeout value in your stack so you know what "too slow" means here:
max_execution_timefor PHP,request_terminate_timeoutfor PHP-FPM, and the gateway timeout for nginx.
Fix the batch
- Spread the load.
wp config set DISABLE_WP_CRON true --rawand add a real system cron that hitswp-cron.phpat 5-minute intervals withcurl --max-time 55. Then fast requests stop mounting. - Raise the right timeout for the job, not the site. If a rebuild job needs 300 seconds, raise the PHP maximum for the CLI job only; do not set the web
max_execution_timeto 300. For media-heavy jobs,wp media regeneratefrom CLI is the safe route instead of the in-browser AJAX. - Split the job. Break a giant loop into an event that re-queues itself (
wp_schedule_single_event) per chunk, so each run stays well under the timeout. - Plug memory leaks. A 502 during cron frequently sits next to
memory_limitexhaustion in the log; the loop that failed is the loop that grows. Fix that first, then raise memory. - Verify in isolation.
wp cron event run <hook>runs exactly one event and returns before the gateway; then retest with a curl againstwp-cron.php.
Prevention
- Real OS cron (
DISABLE_WP_CRON) with--max-time, so visitors never time out. - A monitoring alert on the exact phrase
wp-cron.phpin the access log returning 502. - Keep one health check site in place and note scheduled event drift (see the headless cron troubleshooting guide).
The 502 error overview is the broader path to the same gateway limit, and the 504 walkthrough explains the upstream timeout that a slow cron run trips.