'Is it safe to use MongoDB sessions with PHP-FPM (multi-threads)?

I want to use MongoDB sessions to get a causal consistency guarantee. However I use nginx with PHP-FPM which is multi-threaded. Excluding MongoDB documentation https://docs.mongodb.com/v4.2/core/read-isolation-consistency-recency/ specifies "Applications must ensure that only one thread at a time executes these operations in a client session.".

So I'm stuck at this level and I don't really see how to get out of it. The only solution I see is to make PHP-FPM single thread which I obviously do not want for the advantages it provides.

Do you have any ideas ?

Thank you,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source