[PHP-DEV] [RFC karma request] Scope: per-request state (superglobals, locale, timezone) for long-running and async PHP

Hi internals,

Every long-running PHP server (Swoole, RoadRunner, FrankenPHP, phasync, and anything built on fibers) hits the same wall: $_GET, $_POST, $_COOKIE, $_FILES, the default timezone and locale are process-wide, so serving two requests at once means rewriting them behind the application’s back or forbidding their use. The Scope RFC proposes the missing piece: a small class that identifies the logical operation running code belongs to (a request, a job) and keeps that identity across fibers and generators; two secondary votes let the five request superglobals and the default timezone/locale follow the scope, so unmodified code sees its own request.

I’d like RFC karma for my wiki account, frodeborli. I’ve already submitted a karma request a few days ago so this is a nudge with some more details to show I’ve done real work on this RFC.

The draft (version 0.7, target 8.7) is readable here while it waits for the wiki: PHP RFC: Scope (draft) - fiber-interop. It comes with a reference implementation released today as a PIE extension for PHP 8.2–8.5, fiber-interop/ext-scope 0.3.0 (GitHub - fiber-interop/ext-scope: Scope: a PHP extension implementing the Scope RFC. Identifies the operation code belongs to, across fibers and generators. · GitHub), implementing the class and both secondary votes with phpt tests, and a userland polyfill with the same tests (fiber-interop/scope 0.3.0). It is in use by several event loops through the fiber-interop adapters, which is where the semantics were worked out and measured.

I intend to publish the draft under https://wiki.php.net/rfc/scope and open discussion here once it’s up. Some of you may remember me from the stream_select() FD_SETSIZE work (php-src #14452).

Thanks,

Frode Børli