Skip to content

Make bundle compatible with FrankenPHP worker mode#354

Merged
gregurco merged 1 commit into
8p:masterfrom
nowo-tech:frankenphp-worker-compatibility
Jul 21, 2026
Merged

Make bundle compatible with FrankenPHP worker mode#354
gregurco merged 1 commit into
8p:masterfrom
nowo-tech:frankenphp-worker-compatibility

Conversation

@HecFranco

Copy link
Copy Markdown
Contributor

This pull request ensures EightPointsGuzzleBundle is safe to use in long-running PHP workers such as FrankenPHP worker mode (and similar runtimes where the Symfony container survives across HTTP requests).

Without proper service reset, singleton Guzzle clients and in-memory loggers can leak state between requests—leading to unbounded memory growth and unintended cookie sharing.

Q A
Bug fix yes
New feature no
BC breaks no
Deprecations no
Tests pass yes
Fixed tickets
License MIT

Motivation

In FrankenPHP worker mode, the PHP process and the service container remain alive between requests. Symfony relies on services tagged with kernel.reset to clear request-scoped state.

Prior to this change:

  • The in-memory Logger accumulated messages (including request/response bodies) and was only cleared during profiler collect().
  • HttpDataCollector::reset() did not clear attached loggers, so kernel.reset without collect() left buffers intact.
  • With options.cookies: true, Guzzle kept a CookieJar on the singleton client, allowing cookies to leak across unrelated Symfony requests.

Changes

Logging & profiler

  • Logger and DevNullLogger implement Symfony\Contracts\Service\ResetInterface.
  • Logger services are tagged with kernel.reset (method: reset).
  • HttpDataCollector::reset() also clears attached loggers, covering the case where reset runs without collect().

Cookies

  • When options.cookies: true, the extension injects a dedicated GuzzleHttp\Cookie\CookieJar service.
  • That jar is tagged with kernel.reset (method: clear), so cookies are wiped between requests.

Documentation

Backward compatibility

Fully backward compatible. No public API changes are required for consuming applications.

  • Existing configurations continue to work as before.
  • cookies: true remains supported and becomes worker-safe.
  • Reset behavior is transparent under Symfony’s standard request lifecycle.

Testing

  • Unit tests updated/added for Logger::reset, DevNullLogger::reset, collector reset without collect(), kernel.reset tags, and resettable cookie jars.
  • Full PHPUnit suite: 158 tests, 481 assertions — all passing.
  • CI matrix (PHP × Symfony) on this branch.
  • Optional smoke test under FrankenPHP worker: enable logging, issue N requests, confirm stable memory and no cross-request cookie leakage.

Checklist for reviewers

  • Confirm kernel.reset tags on logger and cookie jar definitions.
  • Confirm no BC impact for apps that do not use workers.
  • Confirm documentation accuracy for production recommendations (logging / profiling tied to %kernel.debug%).

@HecFranco
HecFranco force-pushed the frankenphp-worker-compatibility branch from 112b948 to f4096b1 Compare July 18, 2026 08:52
Reset in-memory log buffers and cookie jars between requests via
kernel.reset so singleton clients do not leak state in long-lived workers.
@HecFranco
HecFranco force-pushed the frankenphp-worker-compatibility branch from f4096b1 to 46c2171 Compare July 18, 2026 08:52
@HecFranco

Copy link
Copy Markdown
Contributor Author

Hi maintainers,
Thank you for your time and for maintaining this bundle.
This PR makes the bundle safe for long-running workers (e.g. FrankenPHP worker mode) by resetting in-memory log buffers and cookie jars between requests via kernel.reset. There are no BC breaks.
I would appreciate it if you could review and approve this MR when you have a moment.
Thanks again!

@gregurco

Copy link
Copy Markdown
Member

@HecFranco thanks for the contribution 👏

@gregurco
gregurco merged commit 85e30d1 into 8p:master Jul 21, 2026
16 checks passed
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.

2 participants