Re: mssql_* overhead

From: Date: Wed, 10 Jan 2007 17:25:41 +0000
Subject: Re: mssql_* overhead
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-246851@lists.php.net to get a copy of this message
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)? They are not sharing the $GLOBALS array(), because the instance $GLOBALS is on a per-connection/page-request basis. The data stored in the $GLOBALS is unique to that one request and dumped at the end of that request
$_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. So, it doesn't actually stay open throughout the whole user session. He didn't say that it wasn't possible to 'store' the variable there. but afaik it is impossible to 'retain' the 'same' resource connection over the duration of a users SESSION ( not one page call, but many calls )
You said yourself that you are opening a new connection to the DB each time you make a call, then close that connection. As far as your description leads me to believe that you are not reusing the same connection. $_SESSION - From the manual: Variables which are currently registered to a script's
                    session.
           From me: persisting data over multiple page requests,
                    ie: PHPSESSID, login_name, authenticated, etc...
$GLOBALS - From the manual: Contains a reference to every variable which is currently
                    available within the global scope of the script.
          From me: existing only on a per-page request.  What ever you have in here is
                    tossed at the end of each page request,
                    ie: DB connections, File Handlers, etc...
So, moving it from the SESSIONs Super Global to the GLOBALS Super Global would be suggested. Jim
Does anyone see a problem with doing it this way? Security concerns? Anything? Thanks in advance, ~Philip
--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#246851) next »