First off, please read some of my other posts, because I have tried to 
straighten out some 
of the confusion generated by these questions.  Unless you're dealing with a 
1985 era 
computer, or a website serving thousands of pages a minute, memory is just not 
going to 
be an issue for you.  Period.  End of story.  PHP is very efficient and has 
excellent garbage 
cleanup.  

No need especially to go unsetting your session variables at the end of each 
page.  In fact, 
this makes no sense unless you don't need that var anymore.  As for appending 
vars to 
your links with javascript, that's really the hard way to do things.  PHP 
sessions will do that 
for you.

Lastly, every MySQL connection you create will be closed when the script ends.  
You can 
explicitly close your db connection out of good form, or not.  It doesn't 
matter, although I 
always prefer good form over bad, myself.  But that's just me....







--- In [email protected], David Halliday <[EMAIL PROTECTED]> wrote:
>
> Hi Rob,
> Thank you so much for the detailed and informative
> reply.  Just a couple of points and a thought
> (question really), please:-
> 
> 1. You said:
> "
> Your will be using memory regardless  of weather you
> are using it as PHP variables within a script or as
> PHP variables registered into a session so it is more
> an issue of how long you are storing the variables for
> and how many concurrent threads you have."
> 
> True but in the case of php variables, they are
> cleared as soon as the script in question end .. I
> think!
> 
> As for "concurrent threads", I was wondering how one
> could control, e.g. increase, the number of allowed
> concurrent threads?  Is it possible programmatically
> or is it a server limitation imposed by the webhosting
> company?
> 
> 2. In this particular application, it would not be
> possible to pass the values via url because there are
> so many of them.  Having read your reply, I think  it
> is best to register the session variable and when the
> html page is loaded and the variables in question are
> populated, the same session is unregistered at the
> bottom of the page.  One would be using sessions as a
> temporary "carrier" of variables.
> 
> 3. You ask:
> " This leads me to another question that I hope
> someone else can answer ???
> 
> Can you simply register the mySQL connection into the
> session ?? or will the
> connection be closed when a single page completes ???"
> 
> I am not an expert but I think that in such a case
> what would be saved in the session is not the state of
> the connection, e.g. open connection, otherwise one
> would be having an openned connection for a long time.
> 
> The question you asked has prompted me to think of
> something that I have not been able to find an answer
> to by searching the net:
> 
> Say you open a connection and :
> a: retrieve an array from table A
> b: if 'a' is completed, leave the connection open and
> retrieve another array from table B
> 
> and so on ..... then close the connection and RETURN
> the whole lot as one big array to be processed in php.
> 
> The question :  is there a limit on how long a
> connection can be left open?  Is the above safer than
> doing "a" close the connection and then open another
> one to do "b"?
> 
> Thanks once again.
> 
> Kind regards,
> 
> David
> 
> 
> 
> 
> --- [EMAIL PROTECTED] wrote:
> 
> > ----- Original Message ----- 
> > Hello
> > 
> > I have this html page  which is loaded after a user
> > logs in. The variables on that page are populated
> > from
> > one or more rows of data which of course belongs to
> > the user in question.  The user may click a link on
> > the page to change a password or email and when the
> > operation is completed the page reloads again.
> > 
> > Now the way I have been doing this is to pull an
> > array
> > of data from the database *every time* the user
> > loads
> > the page.  I have recently read somewhere on the net
> > that "most of the time is spent in the actual
> > connection with the database .. the remaining
> > operations are relatively insignificant, time-wise."
> > 
> > Would it be safe on memory and overall performance
> > if
> > I stored the array as one session variable instead
> > of
> > several connections with the database?
> > 
> > Would that be a good idea even if the session
> > variable
> > is large? (several rows of values - about 50).
> > 
> > Would greatly appreciate an expert advice.
> > 
> > Regards,
> > 
> > David
> > -----------------------------
> > Hi David,
> >               Your will be using memory regardless
> > of weather you are using 
> > it as PHP variables within a script or as PHP
> > variables registered into a 
> > session so it is more an issue of how long you are
> > storing the variables for 
> > and how many concurrent threads you have.
> > 
> > If you are going to register variables into a
> > session and keep that same 
> > session and variables sitewide then you are going to
> > have a lot of 
> > concurrent treads that are keeping these variables.
> > It may well be the case 
> > that you use these variables on many pages anyway so
> > registering them into 
> > the session may be no big deal.
> > 
> > Generally if I have non-sensitive information that
> > as to be passed between a 
> > small number of pages then I append them as GET or
> > POST methods into the 
> > pages them selves. ie -
> > <input type="hidden" name="data" value="100"
> > <input type="hidden" name="userid" value="123"
> > OR
> > <a href="nextpage.php?data=100&userid=123"
> > 
> > You can get fancy and use unset($_SESSION['xxx']) or
> > session_destroy() but 
> > then you have to include an extra script at the end
> > of every page of the 
> > site -
> > 
> > ------------------
> > some_file.php
> > <?php
> > //
> > $keep_user_data = TRUE;
> > include("session_keeper.php");
> > ?>
> > ------------------
> > some_other_file.php
> > <?php
> > //
> > include("session_keeper.php");
> > ?>
> > ------------------
> > session_keeper.php
> > <?php
> > if($keep_user_data != TRUE){
> > unset($_SESSION["user_data"]);
> > }
> > ?>
> > ------------------
> > There are alternatives to registering an array that
> > will likely use less 
> > memory -
> > ------------------
> > The normal way -
> > <?php
> > query$ = "SELECT ...
> > $handle = mysql_connect(...
> > $result = mysql_query($handle, $query ...
> > foreach($result as $row){
> > foreach($row as $key => $value){
> > myarray[][$key] = $value;
> > }
> > }
> > session_register($myarray);
> > ...
> > -------------------
> > A sort cut -
> > <?php
> > if (!isset($_SESSION["result"])){
> > query$ = "SELECT ...
> > $handle = mysql_connect(...
> > $result = mysql_query($handle, $query ...
> > session_register($result);
> > }
> > 
> > foreach($_SESSION["result"] as $row){
> > foreach($row as $key => $value){
> > userdata[][$key] = $value;
> > }
> > }
> > ---------------------
> > This leads me to another question that I hope
> > someone else can answer ???
> > 
> > Can you simply register the mySQL connection into
> > the session ?? or will the 
> > connection be closed when a single page completes
> > ???
> > 
> > ---------------------
> > ???????
> > <?php
> > if (!isset($_SESSION("handle))){
> > $handle = mysql_connect(...
> > session_register($handle);
> > }
> > 
> > $query="...
> > mysql_query($handle, $query ...
> > 
> > Thanks, Rob.
> > 
> > 
> > 
> > 
> > Community email addresses:
> >   Post message: [email protected]
> >   Subscribe:    [EMAIL PROTECTED]
> >   Unsubscribe:  [EMAIL PROTECTED]
> >   List owner:   [EMAIL PROTECTED]
> > 
> > Shortcut URL to this page:
> >   http://groups.yahoo.com/group/php-list 
> > Yahoo! Groups Links
> > 
> > 
> > 
> > 
> > 
> 
> 
> 
>       
>       
>               
> ___________________________________________________________ 
> New Yahoo! Mail is the ultimate force in competitive emailing. Find out more 
> at the 
Yahoo! Mail Championships. Plus: play games and win prizes. 
> http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
>


Reply via email to