arborint wrote:Again, lazy loading, reducing connection overhead, etc. are really unrelated to Singleton. And as also noted, your solution is really to use a global, not a Singleton to solve your problem.
Yes, I did not say lazy loading and such would be related to Singletons.
arborint wrote:Almost always when you use an object you only want one of that object.
Try telling that to the big world of PHP coders
I said it, because the server execution time of a popular shop site I had a look at dropped by roughly 28% after using Singletons. The reason was bad coding within the application and singletons fixed that bad practise. It was not the only way to "fix" the problem, but Singletons were handy.
josh wrote:Personally I'd be worried about the optimization of the SQL going over the connection first.
That one depends so much on the situations. Simple, efficient and small number of queries will not be as bad as multiple connections to the database. Especially if you work with SSL/TSL and remote servers and hundreds of concurrent connection establishments.
One month ago I saw my friend writing a script, which is an Ebay like script and it had this code (something like this):
Code: Select all
$db = new db;
$db2 = new db;
$db3 = new db;
$db4 = new db;
And btw, the constructor initialized the connection to the database. The constructor ate around 95% of the execution time.
allspiritseve wrote:If someone's establishing another connection to the database, they're doing so explicitly.
People explicitly write inefficient and insecure code, I have experienced that way too many times
