On 01/10/2025 14:55, Kamil Tekiela wrote:
This sounds better, but I would argue that if it's a PERSISTENT
connection, then it should be impossible for the user to close it. The
idea is that the connection should remain open after being established
and should only close when the server restarts. What scenario would
necessitate the user to close a connection that should never close?
As I understand it, at least in the case of MySQL, the state of
persistent connections is not managed by MySQL, but by the client (PHP).
This means that it's (at least theoretically) possible for a connection
to end up in an undesirable state, in which case there should be a way
to close it so it's not reused.
I think a disconnect method should be provided, with the proviso that
there should be prominent warnings regarding state management on the
documentation.
I've seen developers getting into trouble after attempting to implement
automatic reconnection in their code with the existing PDO capabilities,
so this already happens anyway.
If something is primarily a footgun, I can see that as reasoning for not
providing it. But a kitchen knife is equally apt at cutting food and
fingers. The latter is not a good reason to not have one in the kitchen
- people can learn to use them safely with adequate instruction.
---
As an aside, the manual is unclear on how much management of persistent
connections PDO does. I have an open issue on this:
https://github.com/php/doc-en/issues/4540
(I did have a brief look again and based on some further investigation I
did based (initially) on the answer thecotne gave in the above linked
issue, believe that answer may not be accurate, at least in its
reasoning, and thus their conclusion is circumspect. Looking at this
again is somewhere on my todo list, I think)