Feature: Add request context providers for long-lived runtimes#96
Open
glensc wants to merge 14 commits intoperftools:mainfrom
Open
Feature: Add request context providers for long-lived runtimes#96glensc wants to merge 14 commits intoperftools:mainfrom
glensc wants to merge 14 commits intoperftools:mainfrom
Conversation
This was referenced May 9, 2026
4df1968 to
1e2cc79
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a request-context abstraction so profiler metadata (URL, query/env/server snapshots, timestamps) is captured at profiling start rather than relying on mutable globals at shutdown—improving correctness for long-lived PHP runtimes.
Changes:
- Add
RequestContext*abstractions, a default provider, and a factory to select a configured provider. - Update
ProfilerandProfilingDatato capture/pass request context fromenable()/start()throughdisable()/stop(). - Update defaults/docs/autoloader and adjust tests to use explicit request-context objects.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/TestCase.php | Adds a helper to build RequestContextInterface instances for tests. |
| tests/ProfilingDataTest.php | Stops mutating globals; passes explicit request contexts into ProfilingData. |
| src/RequestContextFactory.php | Creates a request-context provider from config (or default). |
| src/RequestContext/RequestContextInterface.php | Defines the request-context contract (url/query/env/server snapshot). |
| src/RequestContext/RequestContext.php | Implements an immutable request-context value object with HTTP/CLI constructors. |
| src/RequestContext/Providers/RequestContextProviderInterface.php | Defines provider hook for capturing request-scoped metadata. |
| src/RequestContext/Providers/DefaultProvider.php | Default capture implementation using superglobals / CLI argv fallback. |
| src/ProfilingData.php | Builds meta from captured context instead of reading globals at shutdown. |
| src/Profiler.php | Captures context at enable() and passes it into ProfilingData at disable(). |
| README.md | Documents long-lived runtime guidance and custom request-context providers. |
| examples/autoload.php | Exposes profiler.request_context_provider example config knob. |
| config/config.default.php | Adds default config entry for profiler.request_context_provider. |
| autoload.php | Requires newly added request-context classes for non-Composer usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Provide a concrete request snapshot for HTTP and CLI contexts
Capture HTTP and CLI request metadata from superglobals
Instantiate the default provider when config omits one
8d320f8 to
4345625
Compare
| 'profiler.exclude-env' => array(), | ||
| 'profiler.exclude-all-env' => false, | ||
| // Set this to an implementation of | ||
| // Xhgui\Profiler\RequestContext\Providers\RequestContextProviderInterface |
Comment on lines
+155
to
+159
| $context = $this->requestContext; | ||
| $this->requestContext = null; | ||
| $this->running = false; | ||
|
|
||
| return $profile->getProfilingData($profiler->disable()); | ||
| if (!$context instanceof RequestContextInterface) { |
1c37f9c to
2038836
Compare
- Explain how long-lived runtimes should capture request data - Show the new provider hook in the example configuration
Stop mutating global env and server state in profiling tests
2038836 to
f6a3dc1
Compare
f6a3dc1 to
f924d85
Compare
Verify disable still clears state after the backend profiler stops
29f48da to
a3ab8f2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Details
RequestContextInterface,RequestContext,RequestContextProviderInterface,DefaultProvider, andRequestContextFactoryProfilerto capture request context onenable()/start()and pass it intoProfilingDataonstop()ProfilingDatato build metadata from the captured context instead of reading mutable globals at shutdownprofiler.request_context_providerconfig support