Do you use persistent connections? IF not, then you really shouldn't worry too much about closing your connections. From manual
Using mysql_close() usually not needed, since fake open links are automatically closed at the end of the script. Seeing also freeing up resources.
Instead of too many open connections, could it not be (which is essentially the same) that you have too many open connections? For example, too many users on your site at once?
If you have persistent connections, don't forget about this:
mysql_close () will not close permalinks created by mysql_pconnect ().
As the comment says, it is unlikely that the mysql_connect() resource is not freed at the end of the script. From another page
Release of resources
Thanks to the reference counting system with the PHP 4 Zend Engine, a resource of no more links to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely required to free memory manually.
Note. Permanent database links are an exception to this rule. They are not destroyed by the garbage collector. See the Persistent Connections section for more information.
However, there may be a side effect from the comments on the mysql_close page mysql_close
At least with PHP5.3.2 and Windows tcp connection, you should always use this function mysql_close () to close and release the tcp connector used by PHP. Garbage collection after script execution does not close tcp socket on its own. The socket would otherwise remain idle for approximately 30 seconds, and any additional download / connection pages of an attempt would only add to the sum the number of open tcp connections. This latency does not seem to be configured using PHP settings.
source share