|
| 1 | +--- |
| 2 | +applyTo: "system/Boot.php,system/CodeIgniter.php,system/Commands/Worker/**,system/Config/BaseService.php,system/Config/Factories.php,system/Config/Factory.php,system/Config/Services.php,system/Database/Config.php,system/Database/BaseConnection.php,system/Database/ConnectionInterface.php,system/Database/*/Connection.php,system/Events/Events.php,system/Session/**,system/Cache/**,system/HTTP/**,system/Filters/**,system/Router/**,system/Security/**,system/Debug/Toolbar.php,system/Debug/Toolbar/**,app/Config/WorkerMode.php,tests/system/Commands/Worker/**,user_guide_src/source/installation/worker_mode.rst" |
| 3 | +--- |
| 4 | + |
| 5 | +# FrankenPHP Worker Mode |
| 6 | + |
| 7 | +Use `system/Commands/Worker/Views/frankenphp-worker.php.tpl` as the canonical |
| 8 | +Worker Mode entry point. `worker:install` publishes this template to |
| 9 | +`public/frankenphp-worker.php`. |
| 10 | + |
| 11 | +When changing bootstrap or request-lifecycle code, trace all three Worker Mode |
| 12 | +phases: |
| 13 | + |
| 14 | +1. One-time process bootstrap through `Boot::bootWorker()`. |
| 15 | +2. Per-request preparation: reconnect database and cache connections, reset |
| 16 | + the `CodeIgniter` instance, and replace all request superglobals before |
| 17 | + calling `$app->run()`. |
| 18 | +3. Post-request cleanup: close the session, clean up unfinished database |
| 19 | + transactions, reset factories and non-persistent services, clean up event |
| 20 | + listeners and performance logs, and reset the debug toolbar. |
| 21 | + |
| 22 | +- Preserve the phase ordering unless the change explicitly proves a different |
| 23 | + order is safe. |
| 24 | +- Check every new mutable static property, singleton, shared service, event |
| 25 | + listener, connection, handler, or global for cross-request state leakage. |
| 26 | +- Do not preserve a service across requests merely for performance. Persistent |
| 27 | + services must be safe to reuse and must not retain request, response, user, |
| 28 | + route, security token, locale, or error state. |
| 29 | +- Ensure exceptions and early exits cannot skip cleanup needed before the next |
| 30 | + request. |
| 31 | +- For state-isolation fixes, prefer a regression test that exercises two |
| 32 | + sequential requests or reset cycles in the same process and proves the |
| 33 | + second request cannot observe the first request's state. |
| 34 | +- If the template contract changes, update focused assertions in |
| 35 | + `tests/system/Commands/Worker/WorkerCommandsTest.php`. |
| 36 | +- If existing installations need the new generated entry point, update the |
| 37 | + changelog and upgrading guide and instruct users to run |
| 38 | + `php spark worker:install --force`. |
0 commit comments