Robert Cummings wrote:
On Sat, 2006-04-01 at 21:39, Jasper Bryant-Greene wrote:
Robert Cummings wrote:
There's smart lazy programming, and sloppy lazy programming. I don't
trust anything magical in PHP. Most of us are familiar with the magic
quotes and global vars fiascos *LOL*. But hey, if you can squeeze a
rewrite of an application out of a client for relying on dirty
techniques, who am I to critique your forward thinking manipulative
methods -- not to say that's your intent -- but I'd sure question your
motives and judgement if it comes around ;)
I very much doubt PHP will ever enforce the closing of resources such as
database connections at the end of every script. That would be a
needless BC break.
I'm sure that was the thought on magic quotes and register globals also.
If PHP didn't close connections at the end of scripts we'd either have
just about every script in the world throwing errors when they finished,
or lots of memory leaks. Neither is particularly favourable, so I don't
think it will happen any time soon...
Also, I do it this way because some projects that use my framework want
persistent connections. If my framework closed connections automatically
then that wouldn't be possible.
Your database layer should handle whether a connection is really freed.
Just because the developer calls the close() method on your DB object,
doesn't mean you need to close the connection. But if they don't call a
close() method, then in the future if you do need that functionality...
it's not there.
Of course, it wouldn't exactly be a rewrite to make it close the
connection at the end of every script before PHP did, if I'm proven
wrong and it one day is necessary. I'd only need to change the database
objects layer.
Wrong, you would just be doing the same thing PHP does... closing the
connection at the end of the script. What happens if you need to open 20
connections to 20 different databases... are you going to keep them all
open? I guess you would since it sounds like you don't have a facility
to close them. I don't think what you're doing is incredibly obscene, I
mean 90% of PHP developers are doing the same thing. 90% of the coding
population can't be wrong... but one that same line of thought... when
you open an image file or text file for reading or writing... do you
close it? Or just leave it open for PHP to close at the end? I mean PHP
will magically close all resources for you, there's obviously no need to
close it... or maybe there are valid times when you need to close a
resource yourself, I dunno, I feel like I'm out on a limb here ;)
Yeah, I can see your point. Simple answer though: my framework isn't
designed for connecting to 20 different databases :) It's designed for
normal database-driven websites -- where there usually a maximum of two
connections (master and slave), and often only one connection, open.
I guess I'm just gambling the time-saving benefits of not having to call
$db->close() or whatever all the time, against the slim possibility that
I might one day have to write a new framework to deal with apps that do
20+ DB connections at once. The framework is fairly light anyway as it's
built on top of PDO, so a rewrite is not a huge deal.
--
Jasper Bryant-Greene
General Manager
Album Limited
http://www.album.co.nz/ 0800 4 ALBUM
jasper@xxxxxxxxxxx 021 708 334
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php