Closing MySQL Connections

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hey all,

Here's a question for you, my hosts have told me that that one my pages,
php, was causing their server to reboot because there were too many open
connections and that they should be closed.

Now, correct me if I am wrong but I thought that the connections were closed
after a minute of inactivity.

Does this sound right? Could open connections cause their server to reboot a
lot, say 3 times in 15 minutes? If so, what can I do about it?

Any insight is welcome,


Re: Closing MySQL Connections

Anthony schrieb:
Quoted text here. Click to load it

Hi Anthony,

usually you always should issue the statement mysql_close() at the end
of each php- page. This closes the mysql connection that got opened
during the script.

In case you use the command mysql_pconnect() to connect to MySQL you
must(!!) use mysql_close() at the end as otherwise your connections
will be left open for x amount of time. How long should be defined
somewhere in the ini-files of MySQL but I'm not sure where.

Otherwise and recommended practice is the command mysql_connect() as a
means to connect to MySQL as at the end of the script the recently
opened connection gets closed automatically and no mysql_close() is
needed but, of course, still should be issued.

To answer your question whether it is possible that too many open
connections can cause a server to reboot I can't give you any input but
to me this sounds logical. Of course the definition of "how many is too
many" depends on many different things and the question how often a
reboot might be required depends on the amount of traffic you have on
your website. A lot of traffic = a lot of open connections => server
reboots sooner ;-)



Re: Closing MySQL Connections

Since updating to Mysql 4.1 I see the same problem: my connections are not
anymore automaticaly closed when the PHP program ends. Every time when I
restart my computer and run a MYISAMCHK I get warnings of open connections.

I am afraid that I will have to become religious in closing all connections
before the PHP script ends (and pray that after that it will work).

MySql 4.1: New: yes   Improved: ????


Quoted text here. Click to load it

Re: Closing MySQL Connections

Okay, thanks Wim, looks like I have a few mysql_close($connection) commands
to add to my code.



Quoted text here. Click to load it

Site Timeline