Repository navigation
fix(buffer): persist off the request path and at shutdown - #33
Merged
Merged
Conversation
…use in the startup encryption error
A request that ends before any flush or tick (normal end, exit, uncaught exception, fatal error, out of memory, max_execution_time) now writes its pending items to Redis from a shutdown function registered once when persistence is attached. bin/test_shutdown.php proves each case against a real Redis and documents that SIGKILL and an unhandled SIGTERM run no PHP code.
This was referenced Oct 15, 2026
Closed
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.
Delivers issue: #32
Closes #32
Description
Moves the Redis persist of buffered events and metrics off the request path (adding an item no longer waits on Redis) and makes sure pending items are written whenever PHP can still run code.
persistPending()runs at the end offlushBuffer(), fromtick(), and now from a shutdown function (GuardAgent::persistAtShutdown()) registered once when Redis persistence is attached.Motivation and Context
The write on every add put a Redis round trip, up to the command timeout, on the request path. Deferring it created a window where a request that ends before any flush or tick loses its items. The shutdown function closes that window for normal end,
exit(), an uncaught exception, a fatal error, out of memory andmax_execution_time. SIGKILL and an unhandled SIGTERM run no PHP code, so they are documented as the only cases that lose events. I did not add a SIGTERM handler (it would override the host's) and do not callfastcgi_finish_request()(it would cut off output and shutdown functions the host registers later).Type of change
How Has This Been Tested
bin/test_shutdown.phpspawns a child php per termination mode against a real Redis and asserts the key is present afterwards. On e5e72ce the six PHP-runnable modes fail (0 keys), with the fix they pass. SIGKILL and SIGTERM (no handler) leave 0 keys, and SIGTERM with a host pcntl handler that callsexit()persists.bin/test_agent.php(653 checks), the coverage runner (100%), thephp -lsweep,composer validate --strictandcomposer auditall pass locally on PHP 8.5.Checklist