I am using the singleton design pattern in a PHP application to create a database connection and select the database. I am using this instance many times in the application for CRUD operations.
Is there any problem if my application is accessing the database on multiple threads, such as getting unreliable results?
Is the created instance per session or for all threads?
There are no threads in PHP. Each request start from scratch; objects and resources are not shared.
Unless you have some weird frankenstein setup, all request processed by php are independent and do not share anything. Therefore, the singleton instance is per request (I think that's what you're calling thread).
So you should not have to worry about user A receiving something that was intended for user B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With