When a PHP process connects to MySQL server, the connection can be persistent if your PHP config has
mysqli.allow_persistent. (PDO has the attribute
$dbh = new PDO('DSN', 'KhanhDepZai', 'QuenMatKhauCMNR', [PDO::ATTR_PERSISTENT => TRUE]);
PHP destruct an object automatically when an object lost all its references.
[b] => [d has been killed] => [b] => [e] => [f] => [e has been killed] =>
Instead of using a service object, we should use a factory design pattern for each job (each connection). PHP will close MySQL connection because it destructs object PDO. Then we can reduce the number of connections to MySQL at a same time.
I learned this case when implement a web-consumer (long-run process) to run database migration for multiples databases.
Before fixing this, our MySQL server had been crashed because of a huge opened connections.
Now, everything works like a charm !