Skip to content

Commit a0d743c

Browse files
freddy77SakiTakamachi
authored andcommitted
ext/pdo_dblib: Added dblib_handle_check_liveness handler (php#21681)
Closes php#21681 In case of persistent connection it was not checked if the connection was still alive always assuming it was. If the connection was broken this caused PHP to reuse the broken connection over and over. dbdead function is supported by all dblib implementation (MS, Sybase, FreeTDS). Change tested manually, see FreeTDS/freetds#711 (comment) Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
1 parent 794a35c commit a0d743c

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ PHP NEWS
9999
. Added TLS session resumption support for streams with new context options
100100
and Openssl\Session class. (Jakub Zelenka)
101101

102+
- PDO_DBLIB;
103+
. Added dblib_handle_check_liveness handler. (freddy77)
104+
102105
- PDO_PGSQL:
103106
. Clear session-local state disconnect-equivalent processing.
104107
(KentarouTakeda)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ PHP 8.6 UPGRADE NOTES
204204
. Output of openssl_x509_parse() contains criticalExtensions listing all
205205
critical certificate extensions.
206206

207+
- PDO_DBLIB:
208+
. When using persistent connections, there is now a liveness check in the
209+
constructor.
210+
207211
- Phar:
208212
. Phar::mungServer() now supports reference values.
209213

ext/pdo_dblib/dblib_driver.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,17 @@ static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_valu
420420
return 1;
421421
}
422422

423+
static zend_result dblib_handle_check_liveness(pdo_dbh_t *dbh)
424+
{
425+
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
426+
427+
if (dbdead(H->link)) {
428+
return FAILURE;
429+
}
430+
431+
return SUCCESS;
432+
}
433+
423434
static const struct pdo_dbh_methods dblib_methods = {
424435
dblib_handle_closer,
425436
dblib_handle_preparer,
@@ -432,7 +443,7 @@ static const struct pdo_dbh_methods dblib_methods = {
432443
dblib_handle_last_id, /* last insert id */
433444
dblib_fetch_error, /* fetch error */
434445
dblib_get_attribute, /* get attr */
435-
NULL, /* check liveness */
446+
dblib_handle_check_liveness, /* check_liveness */
436447
NULL, /* get driver methods */
437448
NULL, /* request shutdown */
438449
NULL, /* in transaction, use PDO's internal tracking mechanism */

0 commit comments

Comments
 (0)