PHP中的单例设计

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.

PHP is single threaded. Each time a PHP script is executed it starts from scratch. Objects you create in the script are created anew every time.

There shouldnt be any problems with multithreading because PHP isnt multithreaded.