Hi internals, I'd like to start the discussion on a new RFC:
https://wiki.php.net/rfc/scope PHP has no object that represents a request. The request is the period between startup and shutdown, and its state lives in process-wide globals. That works while a process handles one request at a time, but not when one process serves many requests, and least of all when they overlap. The RFC adds Scope: an object that identifies a unit of work, such as an HTTP request, a queue job or a CLI command. Code can create a scope, run code in it, and ask which scope it is running in: (new Scope())->run($handler, $request); // anywhere in that request: $db = $this->connections[Scope::getCurrent()] ??= new PDO($dsn); Fibers and generators join the scope they are created in, so work a request spreads over several fibers still belongs to that request, whichever library or scheduler created them. Code that never creates a scope runs in the root scope and behaves exactly as today. The primary vote adds only the identity. Two secondary votes move engine state into the scope: A. the request superglobals and the session B. the default locale and timezone Other state (output buffers, error handlers, ini values) is left for later RFCs, so each can be discussed on its own. An extension implementing the RFC, including both secondary votes, is available for PHP 8.2 to 8.5: https://github.com/fiber-interop/ext-scope (pie install fiber-interop/ext-scope) A userland polyfill is fiber-interop/scope on Packagist. A php-src pull request will follow before the vote. I look forward to your feedback. Frode Børli
