so suppose I connect with mysql with my php script as always, however suppose I never really call any code that will close that connection and merely allow it to be before the page is offered towards the user
Can there be any reason I should not do this? What negative effects may arise (if any) basically do that?
Checkout the php option
; http://php.net/mysql.allow-persistent mysql.allow_persistent = On
This ought to help, if you're able to set this.
With respect to the mysql extension you're using not closing the bond is really advantageous because this will permit the employment of persistent connections. Which means the bond is just opened up the very first time the script runs, and each subsequent run the already-open mysql connection can be used, reconnecting when needed. This really is a little faster and fewer resource intensive then frequent lowering and raising the bond on each and every request. If you work with
mysqli then persistent connections ought to be possible and therefore are more suitable.
Even when your mysql extension does not support persistent connections, or is not set up for their services, that simply means the bond will close once the script exits, that is the same as closing it yourself, meaning closing it by hand gains you nothing.
Conclusion: closing the bond yourself most likely gains you nothing and can really hurt performance.
mysqli.allow_persistent to configure whether persistent connections can be used for mysql, based on which mysql extension you're using.
Like every unoptimized code, neglecting to close() or kill() the socket will often not become apparent before the site/application is under heavy demand, i.e., plenty of page demands are now being delivered to the server. By not killing+closing and clearing in the socket following the request continues to be maintained, the socket sits inside a a 'wait' condition for a while of your time, contributing to the burden associated with a new socket connections occurring when new page loads and connection attempts are created. Given high traffic conditions, these electrical sockets continues to amass in process memory, possibly (according to your max connections and max_user_connections params) resulting in the ubiquitous "Max connections arrived at...." message.
Garbage collection that happens following the script has completed won't always recycle the socket endpoint. So far as I understand, only calling mysqli_kill() after mysqli_close() will really get rid of the socket.
For persistent connections, you do not mention which mysql api you are using or even the server and just how php is loaded in to the server and network topology. Persistent connections permit you to steer clear of the overhead of opening an association to mysql. If mysql works on the same box because the web server, persistent connections most likely will not buy much scalability. If php runs inside a cgi process, persistent connections won't work since the php process only is available throughout the duration of the request. Don't confuse persistent connections with JDBC connection pooling, they are different.
Since PHP has garbage collection, once the script finishes around the server, the bond is closed. Unless of course you specified it as being a persistent connection.
In the php reference:
Using mysql_close() is not usually necessary, as non-persistent open links are instantly closed in the finish from the script's execution.
Read more in the mysql_close reference here.