Is it worth it in the php-code after each request to mysql to close the connection to the database, if you consider that the connection is already closed when the script ends?

    2 answers 2

    Let's remember the good old : at the end of the script (end of code / time limit exceeded), the memory occupied by the script will be automatically freed and all MySQL connections except those opened via mysql_pconnect will be closed (if I'm not mistaken). It is not necessary to close the connection after each request, since it takes a lot of time to reconnect, and in the case of uselessness, it is also not necessary to touch, because PHP will close the simple connection on its own at the end of the script. It makes sense to clear the memory of query results using mysql_free_result .

    • It is possible to use a pool of connections. - Alex78191

    After each request, this is not necessary, since after the first request, the next ones will not be executed. It is enough to close the connection after executing the script. Read this at the same time:

    • @admin, thanks for the answer to your words “It’s enough to close the connection after executing the script” - I was once told in Hashcode that the connection closes itself when the script ends. - Deus