Skip to content

Commit 5dfb2d9

Browse files
[pdo_firebird] Added pdo_firebird_check_liveness handler (#12757)
1 parent 927adfb commit 5dfb2d9

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ PHP 8.4 UPGRADE NOTES
231231
Along with these, five constants (PDO::FB_TRANSACTION_ISOLATION_LEVEL,
232232
PDO::FB_READ_COMMITTED, PDO::FB_REPEATABLE_READ, PDO::FB_SERIALIZABLE,
233233
PDO::FB_WRITABLE_TRANSACTION) have been added.
234+
. When using persistent connections, there is now a liveness check in the
235+
constructor.
234236

235237
- PDO_MYSQL:
236238
. getAttribute, enabled to get the value of ATTR_FETCH_TABLE_NAMES.

ext/pdo_firebird/firebird_driver.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,18 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
12161216
}
12171217
/* }}} */
12181218

1219+
#if FB_API_VER >= 30
1220+
/* called by PDO to check liveness */
1221+
static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */
1222+
{
1223+
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
1224+
1225+
/* fb_ping return 0 if the connection is alive */
1226+
return fb_ping(H->isc_status, &H->db) ? FAILURE : SUCCESS;
1227+
}
1228+
/* }}} */
1229+
#endif
1230+
12191231
/* called by PDO to retrieve driver-specific information about an error that has occurred */
12201232
static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
12211233
{
@@ -1254,7 +1266,11 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */
12541266
NULL, /* last_id not supported */
12551267
pdo_firebird_fetch_error_func,
12561268
pdo_firebird_get_attribute,
1257-
NULL, /* check_liveness */
1269+
#if FB_API_VER >= 30
1270+
pdo_firebird_check_liveness,
1271+
#else
1272+
NULL,
1273+
#endif
12581274
NULL, /* get driver methods */
12591275
NULL, /* request shutdown */
12601276
pdo_firebird_in_manually_transaction,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
PDO_Firebird: persistent connect test
3+
--EXTENSIONS--
4+
pdo_firebird
5+
--SKIPIF--
6+
<?php require('skipif.inc'); ?>
7+
--XLEAK--
8+
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9+
See https://github.com/FirebirdSQL/firebird/issues/7849
10+
--FILE--
11+
<?php
12+
13+
/**
14+
* Omit the case where the connection is broken when it checks liveness and
15+
* it has to reconnect, as it is very difficult to reproduce the situation.
16+
*/
17+
18+
require("testdb.inc");
19+
unset($dbh);
20+
21+
$connIds = [];
22+
23+
foreach (['First', 'Second'] as $times) {
24+
$dbh = new PDO(
25+
PDO_FIREBIRD_TEST_DSN,
26+
PDO_FIREBIRD_TEST_USER,
27+
PDO_FIREBIRD_TEST_PASS,
28+
[
29+
PDO::ATTR_PERSISTENT => true,
30+
],
31+
);
32+
$stmt = $dbh->query('SELECT CURRENT_CONNECTION FROM RDB$DATABASE');
33+
$connId = $stmt->fetchColumn();
34+
$connIds[] = $connId;
35+
echo "{$times} connection ID: {$connId}\n";
36+
37+
unset($dbh);
38+
unset($stmt);
39+
unset($connID);
40+
}
41+
42+
echo $connIds[0] === $connIds[1] ? "Same ID.\n" : "Different ID\n";
43+
?>
44+
--EXPECTF--
45+
First connection ID: %d
46+
Second connection ID: %d
47+
Same ID.

0 commit comments

Comments
 (0)