Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anand-moghe's avatar

One singleton service class per user session

I have a need to use unique instances of singleton service class (for which I have my own custom service provider) per user session?

May be I am missing something here but anyone has any ideas about what design patterns or solution approach I can use for this ?

0 likes
1 reply
anand-moghe's avatar

I came to a conclusion that I should be using a session storage to store singleton class within a session. Because as per my understanding PHP is stateless, and every time new request comes to laravel, it must be creating and instantiating a new instance of singleton class every time for a new request and then after serving the response everything dies down I guess.

Please or to participate in this conversation.