[prog] MySQL connections from PHP files - Close or keep it open for queries?

Conor Daly c.daly at met.ie
Tue May 3 23:03:35 EST 2005


On Tue, May 03, 2005 at 09:42:30AM +0000 or thereabouts, Conor Daly wrote:
> 
> On a related note, does anyone know why my ingres_query()s will only run
> consecutively?  If I run two copies of the same application in browser tabs,
> one must complete before the other will happen.  It appears to be a matter
> 
> It seems to be related to 'session_start()' which I'm using to maintain a
> login session for the user.  This seems to be browser dependent.  Eg. If I
> connect with mozilla and get a login page and login, then, when I connect
> with Konqueror, I get the login page again.  

While poking at this further, I'm beginning to see what is wrong.  I use the
following boilerplate code at the top of .php files:

require("validate/validate.php");
if(! $Login) {
   displayLogin($PHP_SELF);
   die();
} else {
   displayLogout("$PHP_SELF");
}

And within validate.php:

// Create the session
session_start();
session_register('Login');
session_register('Password');

Now I use an HTML <FORM> to get Login and Password input, validate against
the database and rerun the original .php script.  This time $Login is set so
the script proceeds.

Now, the second time the poge is loaded by a browser, the sessionid is
checked and the same test occurs only this time, the session is already
registered and so $Login is already set.  However, the second run waits for
the first to complete before it will continue.  

This is probably valid behaviour since you don't want a second copy of a
session clobbering your data midstream.  It seems to me that what I need is
a method to:

1. Check if a session is active
2. If not, start one
3. If so, connect to it, grab the Login, Password info and disconnect from
   it
4. Run the rest of the script apart from the session without expiring the
   session

I've had a look at session_write_close() but that doesn't seem to be doing
it for me...

Is it possible?

Conor
-- 
Conor Daly,                   Please avoid sending me 
Met Eireann, Glasnevin Hill,  Word or PowerPoint attachments.
Dublin 9, Ireland             http://www.fsf.org/philosophy/no-word-attachments.html
Ph +3531 8064276 Fax +3531 8064247

**********************************************************************
This e-mail and any files transmitted with it are confidential 
and intended solely for the addressee. If you have received
this email in error please notify the sender.
This e-mail message has also been scanned for the
presence of computer viruses.
**********************************************************************



More information about the Programming mailing list