0

If i create a singleton class then only one object of that class can be created,now what if two request trying to instantiate the same class,php is a shared nothing architecture so it can not create single object for both request,so will it wait for one request to be completed before serving the another or it will create a separate instance for the other request at the same time?

Tarun
  • 3,162
  • 3
  • 29
  • 45

1 Answers1

3

Each request launches a separate instance of PHP, and when the script has run its course it's torn down and everything is disposed of. This usually happens in some fractions of a second. A "singleton" just means that only one instance of it will be created for each instance/run of the script. There can be many scripts in parallel that each have their own instance of the singleton. A singleton a logical concept, not a hard limit imposed by anything.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • you mean,though multiple request can be served at the same time by server but for those multiple request for the same script will create multiple instance of singleton class,right?please tell me if i did not get you right – Tarun Nov 27 '11 at 06:57
  • Yes, one singleton instance *per* script instance. – deceze Nov 27 '11 at 06:59