PHP, MySQL and sleeping connections

I am running a web service running PHP / MySQL and recently noticed a strange problem.

When I run "show a complete list of processes"; SQL through an SSH terminal, I notice a few dormant connections:

| Id        | User    | Host      | db      | Command | Time | State | Info                  |
+-----------+---------+-----------+---------+---------+------+-------+-----------------------+
| 218121282 | test_user | localhost | test_db | Sleep   |    0 | NULL  | NULL                  |

Do these "sleeping" connections happen because mysql_close () is not used at the end of the scripts?

If this is the reason, can I solve this problem using the PHP function "register_shutdown_function" and running mysql_close () in the callback function?

Thanks for your suggestions.

+3
source share
3 answers

Do these "sleeping" connections happen because mysql_close () is not used at the end of the scripts?

No. MySQL connections are anyway closed at the end of the script, unless they are persistent.

, , , - MySQL , PHP script - .

, , . , , , , . , , , , , , , , ..

+2

(mysql_pconnect())? , .

0

change variables wait_timeoutand interactive_timeoutto small values

can be changed in my.cnf file in centos

0
source

Source: https://habr.com/ru/post/1757612/


All Articles