📝 WordPress: Fix admin-ajax.php Timing Out Under Plugin Load
Every wp.ajax.post() call from the block editor, a form plugin, or a heartbeat check routes through the single shared admin-ajax.php endpoint, which bootstraps the entire WordPress environment — every active plugin, the full theme, and the whole plugin hook system — before it even looks at which specific ajax action was requested. On a site where several plugins each hook into init or plugins_loaded with their own expensive setup (registering dozens of custom post types, warming a cache, calling out to a license-check API), that full bootstrap cost is paid on every single ajax request, not just full page loads, and under concurrent load from something like the editor’s autosave heartbeat firing from several open tabs, those bootstraps queue up behind each other and the request simply times out before WordPress ever reaches the actual ajax handler.
🔎 The Problem
Server access log during active editing with 3 browser tabs open:
POST /wp-admin/admin-ajax.php (action=heartbeat) -> 504, 28.0s
POST /wp-admin/admin-ajax.php (action=heartbeat) -> 504, 27.8s
POST /wp-admin/admin-ajax.php (action=autosave) -> 504, 29.1s
New Relic / query monitor trace for ONE of those requests:
plugins_loaded hook: 22.4s total
- license-check-plugin: 9.8s (blocking HTTP call to vendor API)
- cpt-registration-plugin: 6.1s (file scan on every request)
- cache-warm-plugin: 4.9s
actual ajax action callback: 0.06s <- the real work is instant
âś… Fix: Keep plugins_loaded Light and Make admin-ajax Aware of It
- Move any plugin’s blocking network calls (license checks, remote config fetches) out of
plugins_loaded/initand behind a transient cache with a short TTL, so the expensive call happens once every few minutes in the background instead of synchronously on every single ajax request. - Wrap expensive one-time setup (like a custom post type file scan) in a check for
wp_doing_ajax()combined with the specific$_REQUEST['action']values that actually need it, so unrelated ajax actions like heartbeat don’t pay for work they never use. - Reduce the Heartbeat API’s polling interval via
heartbeat_settingsfilter on the specific admin screens where it’s firing most aggressively, since fewer concurrent heartbeat requests means fewer bootstraps competing for the same slowplugins_loadedwork at once.
🚨 Why This Is Dangerous
- A timing out admin-ajax.php doesn’t just break autosave — it silently breaks every other plugin that shares the same endpoint, including ones with no relation to the slow plugin at all, because the bottleneck is in the shared bootstrap every ajax request has to pass through first.
admin-ajax.php doesn’t care which action you asked for until after it has already paid the full cost of being WordPress — and a fast handler behind a slow bootstrap is still a slow request.





