Forum Moderators: coopster

Message Too Old, No Replies

Is mysql_close necessary in the case of a header redirect?

         

rabbit_fufu

6:27 pm on Feb 28, 2004 (gmt 0)

10+ Year Member



Hi Guys, I'm hoping someone here can help me. Please bare with me as I'm a bit new at this. I have 2 questions...

#1

I've written a php script to do some basic user authentication. As part of the script it opens a connection to mysql using a static handle like so,

$connection=mysql_connect(etc etc)

Then, if some of the auth info in the db is bad, like a timestamp has expired, the script redirects to an appropriate 'expired' page using a header (Location: etc) redirect.

My question is this: I understand that it is not necessary to use mysql_close in cases where the db connection has been opened with mysql_connect as the connection will end automatically upon termination of the script. However, I also recall reading somewhere that if you jump prematurely out of a script you have to manually close the connection (maybe I'm just hallucinating this, not sure...)

Anyhow, does anyone know if that scenario applies here? Would I need to have a mysql_close($connection) before the header redirect to ensure that the db connection is in fact closed?

Okay... question #2...

Like I mentioned before, I'm using a static handle to establish this connection...

$connection=mysql_connect(etc etc)

Now let's say I also have a mysql_close($connection) in this script...

My question is, what happens if 2 people are accessing the site almost simultaneously... So for example...

Person #1 has connection established...
Person #2 also has connection established (the same connection I think... correct me if I'm wrong...)

Person #1 performs db transaction and then has db closed by mysql_close, before person #2 has had a chance to perform their db transaction...

Basically I'm wondering if using the same handle and then calling mysql_close in places has the potential to shut down the db on a user unexpectedly if multiple users are using the system simultaneously? If so, does anyone know an easy workaround for this?

Okay, thanks for your help, I surely do appreciate it!

-trav

jatar_k

7:43 pm on Feb 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld rabbit_fufu,

Your name reminds me of that song when I was a kid. :)

1. I don't think you need to worry about closing it before you redirect. I think it will close it, though I am not sure. In essence that script has finished and it may be cleaned up anyway.

2. Though the 2 connections may have the same id they are not really the same connection. If you close the connection for one user it won't affect the other user's connection to mysql.