Skip to content

Conversation

@KevinMartinsDev
Copy link

@KevinMartinsDev KevinMartinsDev commented Oct 30, 2025

This Pull Request proposes an update to the documentation to better explain FrankenPHP's Worker Mode.

The goal is to provide clear information regarding:

Associated Risks of state persistence (stateful services) across consecutive requests.

Best practices and tools (such as Symfony's ResetInterface or phanalist) to ensure a successful migration of applications to this high-performance model.

This clarification aims to prevent unexpected behaviors and facilitate the adoption of Worker Mode.

@KevinMartinsDev KevinMartinsDev changed the title Add warning on stateful services and shared memory model docs: Add warning on stateful services and shared memory model Oct 30, 2025
@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from 34f1eea to 3f7bd27 Compare October 30, 2025 11:15
@henderkes
Copy link
Contributor

henderkes commented Oct 30, 2025

Thank you for the contribution, please add the English page as well, as that's the authoritative version.

I'm also not quite happy with the statement that workers introduce a shared-memory model. They don't really do that, they just don't reset the state between requests. They still don't share memory with other parallel requests.

@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from 3f7bd27 to 32abca1 Compare October 30, 2025 12:56
@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from 32abca1 to a7adc67 Compare October 30, 2025 12:57
@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from 777a85e to f9a297a Compare October 30, 2025 13:14
@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from bc43d35 to 911ca08 Compare October 30, 2025 19:19

## Avertissement sur la conception Stateful

Contrairement au modèle PHP-FPM traditionnel, l'application reste chargée en mémoire entre les requêtes. Par conséquent, tout état stocké dans vos services (propriétés d'objet, singletons, etc.) sera conservé et partagé entre les requêtes successives traitées par le même worker. Cela peut entraîner des fuites de données ou des états incohérents si votre application n'est pas conçue pour cela.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Des fuites de données ou de mémoire

## Avertissement sur la conception Stateful

Contrairement au modèle PHP-FPM traditionnel, l'application reste chargée en mémoire entre les requêtes. Par conséquent, tout état stocké dans vos services (propriétés d'objet, singletons, etc.) sera conservé et partagé entre les requêtes successives traitées par le même worker. Cela peut entraîner des fuites de données ou des états incohérents si votre application n'est pas conçue pour cela.
L'article suivant résume ce problème et explique comment y remédier, notamment pour les applications Symfony en utilisant ResetInterface pour garantir que vos services sont "propres" à chaque nouvelle requête.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que vos services sont « réinitialisés »

@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch 2 times, most recently from a6fb2a7 to 75bc5ac Compare November 3, 2025 08:07
@KevinMartinsDev KevinMartinsDev force-pushed the docs/worker-shared-memory-warning branch from 75bc5ac to 8533696 Compare November 3, 2025 08:15
@dunglas
Copy link
Member

dunglas commented Nov 3, 2025

I'm not a fond of the external link. They make the info harder to find. Couldn't we replace them with some examples?

We should also hint about the Symfony ResetInterface and explain that it's possible to mitigate these issues by configuring a maximum number of requests to handle (that can even be 1).

@KevinMartinsDev
Copy link
Author

Hello 😄 I understand the comment. I have my doubts too, but I thought it would be better to cite my source than just copy and paste. I'll take a look at that. I have already tried setting the maximum number of requests to 1, but then the benefit of worker mode is minimal or even non-existent in terms of performance, or am I wrong?

Another question: is there a risk with libraries installed in a project? Even if I implement security measures in my code to ensure that I am managing statelessness correctly, how can I be sure that the problem cannot come from elsewhere?

@KevinMartinsDev
Copy link
Author

Hello 😄 , do you have any other feedback? @dunglas @alexandre-daubois @94noni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants