mysql_close() - necessary?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

mysql_close() - necessary?

Post 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?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Quick reply which also falls in line with my lazy approach. Thanks, Eric :)
Post Reply