Skip to content

Frontend output-buffer handler fatals during image format replacement #1126

Description

@pirate-bot

Summary

Optimole can trigger a fatal error while processing frontend output: Optml_Manager::replace_content(): Cannot use output buffering in output buffering display handlers.

Expected behavior: Frontend HTML is processed and image URLs are rewritten without a fatal error.

Actual behavior: The request terminates while Optimole's content-replacement handler is running.

Impact: Affected frontend requests cannot complete normally, preventing the optimized page response from being served.

Customer context

  • Product / area: Optimole WordPress frontend content and image URL replacement
  • Version: 4.2.11
  • Environment: WordPress 7.1; PHP 8.1.2
  • Integration / third party: Optimole PHP SDK 1.2.4; ThemeIsle SDK 3.3.58
  • Reported error / symptom: Optml_Manager::replace_content(): Cannot use output buffering in output buffering display handlers
  • Impact: Four telemetry occurrences across two production sites between 2026-08-29 and 2026-08-30.

Reproduction notes

  1. On a frontend request, Optimole registers its full-page output-buffer callback through process_template_redirect_content().
  2. Process HTML containing an image URL through replace_content() with URL formatting active; best-format mode is one reachable path in the inspected code.
  3. Telemetry reports the fatal Optml_Manager::replace_content(): Cannot use output buffering in output buffering display handlers during this processing.

Reproduction has not been run locally because the checkout lacks the WordPress test runtime and bundled vendor directory. The production crash was recorded four times across two sites.

Diagnosis

Conclusion

Production telemetry provides direct evidence of a frontend fatal in the Optimole content-replacement output-buffer handler. The inspected 4.2.11 source registers that handler and routes image formatting through the locked Optimole PHP SDK. The SDK revision's FormatProperty is a value object with no output-buffer operation, so the crash is not supported as a defect in the shared ThemeIsle SDK.

Where this likely occurs

  • inc/manager.phpOptml_Manager::register_hooks() lines 400-410 registers process_template_redirect_content() for frontend requests and close_buffer() at shutdown.
  • inc/manager.phpOptml_Manager::process_template_redirect_content() lines 793-817 starts an output buffer whose callback invokes Optml_Manager::replace_content() at line 815.
  • inc/manager.phpOptml_Manager::replace_content() lines 441-533 processes full-page HTML and delegates URL processing at line 527.
  • inc/manager.phpOptml_Manager::do_url_replacement() approx. lines 748-787 applies the optml_content_url filter at line 778 while the display handler is active.
  • inc/url_replacer.phpOptml_Url_Replacer::build_url() lines 271-294 creates an SDK image resource and calls Image::format() when a format is selected or best format is enabled.
  • composer.lock — package entry lines 10-15 locks codeinwp/optimole-sdk to v1.2.4, commit 2f7a48525014bd681f39ddc85c55521b719d5879. External reference inspection of that exact dependency revision found src/Resource/ImageProperty/FormatProperty.php only stores and stringifies the format.

Engineering notes

  • The telemetry location resolves to the bundled Optimole SDK's FormatProperty.php, but the report explicitly marks it as outside ThemeIsle SDK code. The inspected dependency source does not contain output-buffer calls.
  • The product code keeps the output buffer open until Optml_Manager::close_buffer() flushes it at shutdown, so callbacks reached by image URL processing execute in a PHP output-buffer display-handler context.
  • The current production signal has no structured stack trace. It confirms the fatal and handler context but does not identify which call in the reachable replacement/filter chain initiates the prohibited output-buffer operation.
  • Commit bd94c770378d03718cac7fa1aa0e3fc4814c63df changed the shutdown hook priority to prevent buffer-flush conflicts and is included in releases from v4.2.2 through v4.2.11. The available evidence does not establish a previously working version boundary for this crash.

Test coverage status

tests/test-replacer.php exercises Optml_Manager::replace_content() directly, including Test_Replacer::test_optimization_url() at lines 217-226. No relevant coverage for process_template_redirect_content(), its output-buffer callback, or shutdown flushing was found during inspection.

What to verify or explore next

  • Reproduce on PHP 8.1 with Optimole 4.2.11 by exercising frontend full-page replacement with image format selection or best-format enabled.
  • Capture a full stack trace or a minimal plugin/theme compatibility set from an affected environment to identify the nested output-buffer operation.
  • Run the PHP suite for tests/test-replacer.php and add a runtime check that reaches process_template_redirect_content() and close_buffer() together.
  • Verify whether installed cache, optimization, or page-builder integrations attach callbacks to optml_content_url, optml_image_args, optml_url_pre_process, or optml_url_post_process that start or flush buffers.

Unknowns / follow-up

  • No structured stack trace, request URL, active compatibility-plugin list, or Optimole setting snapshot was captured by the telemetry event.
  • The exact prohibited output-buffer call has not been isolated from the available production report and repository source.

Confidence

Confidence: 88/100

Production telemetry records the same frontend fatal four times on two sites running Optimole 4.2.11. The released code registers replace_content() as the output-buffer callback path, while the locked Optimole SDK's FormatProperty only stores and stringifies a format value; the fault is therefore routed to the Optimole WordPress plugin rather than the shared ThemeIsle SDK.

Crash telemetry

Occurrences 4
Distinct sites 2
First seen 2026-08-29 20:56 UTC
Last seen 2026-08-30 12:28 UTC
Crash location product:vendor/codeinwp/optimole-sdk/src/Resource/ImageProperty/FormatProperty.php:1
Request context frontend
Inside Themeisle SDK no
Product versions 4.2.11
WP versions 7.1
PHP versions 8.1.2-1ubuntu2.25
SDK versions 3.3.58

Source: automated crash report — optimole-wp, fingerprint 4c4b88a0a15d8f02880d0e3b52944af4
Generated by bug-report-triage (ID: bug-report-triage_6a9518fea07883.22014318)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions