Page 1 of 1

mysql_close() - necessary?

Posted: Thu Jul 31, 2003 9:30 am
by patrikG
I used to not worry about closing my mysql-db connection. After all, the PHP-manual totally falls in line with my lazy approach:
PHP Manual wrote:Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.
Great. The connection on the server in question is non-persistent, I am sure of that. Now I've just checked the error-log there and "Too many database-connections" came up at least 10 times during the last month.

I am not an mySQL-guy, but does anyone have a clue why this could have happened?

Posted: Thu Jul 31, 2003 9:33 am
by nielsene
That's happenibg because you have more than N vistors loading your page at one time. Using mysql_close can help, my minimizing the amount of time a script holds a connection open, thereby making it less likely to have overlapping connections. However, unless your scripts are very long I doubt it would make much of a difference.

Posted: Thu Jul 31, 2003 9:36 am
by patrikG
Quick reply which also falls in line with my lazy approach. Thanks, Eric :)