> Le 30 sept. 2025 à 23:07, Larry Garfield <[email protected]> a écrit :
> 
> On Tue, Sep 30, 2025, at 3:08 PM, Claude Pache wrote:
>>> Le 30 sept. 2025 à 17:40, Larry Garfield <[email protected]> a écrit :
>>> 
>>> 
>>> What would be valuable is easier RE-connection logic.  Either PHP or MySQL 
>>> may terminate an idle connection, which is a concern in long-running 
>>> processes (Queue workers, ReactPHP, Franken, etc.).  Tools like Doctrine 
>>> have built their own refresh logic in, although they're not always 
>>> consistent with each other or obvious to use.  Having some kind of 
>>> reconnection logic built into PDO that "just works" would be very valuable.
>>> 
>>> What that would look like, I'm not sure.  Just spitballing:
>>> 
>>> // After X seconds, drop and reopen the connection the next time it's used.
>>> $pdo->reconnectAfter($seconds);
>>> 
>>> --Larry Garfield
>> 
>> Auto-reconnection is dangerous, because database engines are stateful. 
>> For example, disaster will happen if disconnection had occurred in the 
>> middle of a transaction...
>> 
>> —Claude
> 
> All the more reason that the logic should be implemented once in PDO and then 
> shared, rather than everyone having to figure it out in user space themselves.
> 
> I'm not suggesting that PDO actively try to disconnect all the time.  But if 
> the connection is "stale," it should be able to restart it without making the 
> user faff about to do so.  (Whether that's via detecting that it's gone away, 
> a timer, or whatever else, I'm very flexible.)
> 
> --Larry Garfield

Database connections are full of state (apart from transactions, there are also 
sql variables, temporary tables, and probably other stuff I am not aware of), 
thus auto-reconnection cannot be transparent in the general case. In specific 
scenarios, this is ok, but I doubt that it is best managed by a generic 
extension like pdo.

—Claude

Reply via email to