PostgreSQL auto-reconnect in PDO contructor for permanent connections: request for comments
[email protected] (Marc Barilley) Tue, 30 Mar 2010 17:50:29 +0200
| Newsgroups | php.pdo |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'm new to this list so please excuse me if I ask something stupid :) I've searched the mailing list archives but did not see an answer to my question. I'm currently experiencing a mis-feature in the pg PDO driver: when one calls the PDO constructor with permanent connection, the connection status is checked by simply calling PQstatus(). This is not sufficient in some circumstances when a cache effect may occur. When comparing the implementations between PDO::psql and the pg_* functions, I've noticed that the pg_pconnect() functions issue a "SELECT 1" on the link to make sure that the connection is really alive. The MySQL PDO driver does this by calling mysql_ping() on the connection to test it. I've not dig into the other drivers to see how they do that. This is something I'd like to add in the PostgreSQL driver. In order not to break anything in the current implementation, my idea was to add a driver specific constant (named PGSQL_ATTR_DEEP_CONNECTION_CHECK for example, or anything that fits) that would make the driver run a "SELECT 1" when retrieving a connection link from the pool to re-use it: if the connection is actually broken, it would then be re-opened by the subsequent code. The default would be keeping the way it works now. Does this seem reasonnable? Thank you for your comments. Marc Barilley