Skip to content

Commit a7adc67

Browse files
(En)Add warning on stateful services and shared memory model
1 parent 2c14407 commit a7adc67

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/worker.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
Boot your application once and keep it in memory.
44
FrankenPHP will handle incoming requests in a few milliseconds.
55

6+
## A Paradigm Shift: The "Shared Memory" Model
7+
8+
Warning: This mode introduces a new development paradigm. If your code is not stateless, enabling worker mode risks introducing unexpected behavior.
9+
10+
Unlike the traditional PHP-FPM model ("Shared Nothing"), where memory is cleared after every request, FrankenPHP's worker mode uses a "Shared Memory Model".
11+
12+
The application remains loaded in memory between requests. Consequently, any state stored in your services (object properties, singletons, etc.) will be preserved and shared across successive requests handled by the same worker. This can lead to data leaks or inconsistent states if your application is not designed for it.
13+
14+
The following article summarizes this issue very well and explains how to fix it, notably for Symfony applications using ResetInterface to ensure your services are "clean" for every new request.
15+
16+
**Additional Resources:**
17+
18+
* **Article**: [Getting your Symfony app ready for Swoole, RoadRunner, and FrankenPHP](https://dev.to/sergiid/getting-symfony-app-ready-for-swoole-roadrunner-and-frankenphp-no-ai-involved-2d0g) - Explains the problem in detail and presents solutions.
19+
* **Symfony**: [The Messenger](https://symfony.com/doc/current/messenger.html#stateless-worker) documentation also discusses this "stateless worker" concept.
20+
* **Tool**: [phanalist](https://github.com/denzyldick/phanalist) is a static analyzer (mentioned in the article) that can help you detect "stateful" services in your code.
621
## Starting Worker Scripts
722

823
### Docker

0 commit comments

Comments
 (0)