I have been trying to connect MySQL server and close the MySQL connection after query execution from PHP. The queries gets executed successfully, but it appears the connection is not getting closed/released in MySQL server.
I am using the below code to execute the query:
<?php
$dbhost = 'p:127.0.0.1';
$dbuname = 'database';
$dbpass = 'password';
$database = 'user';
$port = '3306';
$conn = new mysqli($dbhost, $dbuname, $dbpass, $database, $port);
$conn->close();
?>
When I am checking my process list in MySQL it is showing that the process is in sleep state:
mysql> show full processlist;
+----+----------+--------------------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+----------+--------------------+------+---------+------+-------+-----------------------+
| 61 | user | 127.0.0.1:52411 | database| Sleep | 5587 | | NULL |
| 62 | root | localhost | NULL | Query | 0 | init | show full processlist |
+----+----------+--------------------+------+---------+------+-------+-----------------------+
I had used var_dump of the connection and found that it was closed in PHP successfully. My project environment are given below.
PHP : 8.0.20 , MySQL: 8.0.29
Note: In my production server I have limit to maximum active connection to 20. According to business logic I have to create a new connection and execute the query each time. But since the connection limit is 20 it gets overloaded too fast as the previous connections are not getting closed.