Repository navigation
Conversation
…ript Worker SAPIs run one script that serves many requests, so RINIT and RSHUTDOWN don't run between them, and the SAPIs reset other extensions' globals by hand. php_request_end() and php_request_begin() run the output, SAPI and superglobal steps of php_request_shutdown() and php_request_startup() without ending the script, and call the new request_end_func and request_begin_func module hooks. php://input streams hold a reference to the request body, and freeing the body clears SG(request_info).request_body, so php_request_end() can release it.
…ame script The URL rewriter state drives the response output handler: without a reset, output_add_rewrite_var() never restarts the handler after the first request and its variables accumulate. Other state, such as strtok(), the stat cache or putenv() changes, is shared by the requests as in a long-running script.
…me script The session is written and closed and $_SESSION is removed, keeping the save handlers registered by the script. session.auto_start starts the session of the next request.
…ame script ext/filter keeps a copy of each input variable it parses, freed only by RSHUTDOWN. sapi_activate() drops these copies without freeing them, so a script serving several requests leaked them on each request.
php_rehash_environment() replaced the superglobals of the finished request once the output of the next one was active, so the destructors of the objects stored in them wrote to the next client's response, and data put back by those destructors leaked into the next request. php_request_begin() now releases them, and $_SESSION, before the output of the next request is active. The script still reads the superglobals of the finished request until then, as worker runtimes document.
Code running between two requests served by the same script, like the worker loop or a destructor, can set request state after php_request_end(). sapi_activate() dropped the header callback, headers, status line, mimetype and php://input body without releasing them, and the next request inherited the URL rewriter state and the session. php_request_begin() now releases the SAPI state before the output of the new request is active, and the standard request_begin hook resets the URL rewriter. session_start() and session_id() refuse to start or name a session when no request is active, as no client would get it. php_request_begin() sets SG(sapi_started) like php_request_startup().
A failing request_startup_func ends the process, while php_request_begin() and php_request_end() ignored failing hooks and the script kept serving requests with state its extensions couldn't set up or release. Both now return FAILURE when a hook fails or a step bails out, so the SAPI can end the script. zend_test gets request hooks that fail on demand.
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.
RFC: https://wiki.php.net/rfc/request_lifecycle_hooks
Discussion: https://news-web.php.net/php.internals/133044