Philip Thompson wrote: > On Jan 10, 2007, at 10:09 AM, Jochem Maas wrote: > >> Philip Thompson wrote: >>> Hi. >>> >>> Does anyone know if the mssql_connect/_init/_bind/etc require a lot of >>> overhead? >>> >>> I have a page that requires multiple function calls and each of those >>> opens a new connection to the database, performs the necessary actions >>> in stored procedure(s), and then closes the connection. However, I found >>> this to be slower than I was wanting. So I thought, just create one >>> connection and assign it to the SESSION (a global), and in each function >>> that requires a connection, call that SESSION variable. At the end of >>> the page, close the connection and nullify the variable. >> >> I wouldn't stick it in the SESSION superglobal (my tactic is usually >> to create >> a little wrapper class to the relevant DB functions and store the >> connection >> as a property of the class/object. >> >> basically opening & closing the connection once per request is the way to >> go - if your going to using a global, better [than $_SESSION] to stick it >> in $GLOBALS imho. > > Would there be any speed decrease with multiple users (hundreds) sharing > this $GLOBALS variable (if that makes sense)? php is a 'share nothing' architecture - there is no concept of sharing data between multiple processes like you might find a java-based web application. (there are caveats, with regard to using SysV shared memory extension and [I believe] some DB extensions do DB connection pooling at a low[er] level) google for 'share nothing' and 'php' and your sure to find *much* better explanations of this than I can/care to give :-) $GLOBALS is only for the current request - it contains a reference to every variable defined in the global scope of the current process, it can't be used/viewed/manipulated by any other process/thread/request/badger. > > >> $_SESSION is used for persisting data over multiple requests - >> something that >> is not possible to do for 'resource identifiers' (which is what the >> connection [id] is). > > BTW, it does work b/c that's how it's currently setup. I am open to > changing it though. I should say, I'm creating at the beginning of the > script and closing it at the end. it works because your not trying to persist the db connection resource identifier between request - which is why is pointless (and possibly a little weird) to use $_SESSION to store the resource identifier in .. then again it's not really doing any harm (it's certainly a whole lot better than building up and tearing down a db connection for every query!) > So, it doesn't actually stay open > throughout the whole user session. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php