Skip to content

Recover from PHP fatal errors and HTML error pages during optimization - #17

Merged
ajaydsouza merged 4 commits into
mainfrom
fix/bulk-error-recovery
Oct 21, 2026
Merged

ajaydsouza merged 4 commits into
mainfrom
fix/bulk-error-recovery

Conversation

@ajaydsouza

Copy link
Copy Markdown
Contributor

Reported in https://wordpress.org/support/topic/two-bug-perhaps-this-is-due-to-an-underpowered-server-or-an-excessive-images/

Bulk Optimize stopped with Unexpected token '<', "There h"... is not valid JSON (a PHP fatal error) or "<!DOCTYPE "... is not valid JSON (a server or proxy error page), and the queue never cleared.

Changes

  • Processor: a fatal error or driver exception while converting is now recorded against the row being processed. The row spends a retry straight away instead of staying claimed for 10 minutes, and the failures table shows the PHP error (file path stripped). The handler hooks wp_should_handle_php_error because WordPress's own handler exits before later shutdown functions run; a shutdown function covers WP_DISABLE_FATAL_ERROR_HANDLER.
  • Bulk Optimize: HTML error pages and network errors are retried up to five times with a growing pause and explained in plain language. Errors returned by the endpoint still stop the run.
  • Media Library Optimize link: same fatal-error recording; an error page is no longer reported as "Connection interrupted".
  • .htaccess install/remove: an error page shows the existing fallback message instead of a JSON parse error.
  • Version bumped to 1.3.0-beta1 for a GitHub beta. Stable tag stays at 1.2.1.

Testing

  • Unit tests for recording fatal errors in QueueStaleTest.
  • php -l, node --check and pnpm run build:assets locally; phpcs, phpstan and PHPUnit run in CI.

Generated by Claude Code

A PHP fatal error while converting an image left its queue row claimed
for ten minutes with no recorded cause, and any non-JSON response
stopped the Bulk Optimize screen with a raw JSON parse error.

- Record a fatal error or driver exception against the row being
  converted, so it spends a retry and the failures table names the cause.
- Retry transient failures (HTML error pages, network errors) up to five
  times with a growing pause, and explain them in plain language.
The Optimize link reported every non-JSON response as a dropped
connection, and a fatal error left the row claimed with no recorded
cause. The .htaccess buttons failed with a raw JSON parse error.
@ajaydsouza
ajaydsouza merged commit c964942 into main Oct 21, 2026
36 checks passed
@ajaydsouza
ajaydsouza deleted the fix/bulk-error-recovery branch October 23, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant