Skip to content

Commit b9a9790

Browse files
committed
Fix phpGH-13519: PGSQL_CONNECT_FORCE_RENEW with persistent connections.
persistent connections did not take in account this flag, after the usual link sanity checks, we remove its entry. Close phpGH-13519
1 parent b8a1041 commit b9a9790

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PHP NEWS
3131
- PGSQL:
3232
. Fixed bug GH-13354 (pg_execute/pg_send_query_params/pg_send_execute
3333
with null value passed by reference). (George Barbarosie)
34+
. Fixed bug GH-13519 (PGSQL_CONNECT_FORCE_RENEW not working with persistent
35+
connections. (David Carlier)
3436

3537
- Standard:
3638
. Fixed array key as hash to string (case insensitive) comparison typo

ext/pgsql/pgsql.c

+7
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
562562

563563
/* try to find if we already have this link in our persistent list */
564564
if ((le = zend_hash_find_ptr(&EG(persistent_list), str.s)) == NULL) { /* we don't */
565+
newpconn:
565566
if (PGG(max_links) != -1 && PGG(num_links) >= PGG(max_links)) {
566567
php_error_docref(NULL, E_WARNING,
567568
"Cannot create new link. Too many open links (" ZEND_LONG_FMT ")", PGG(num_links));
@@ -590,6 +591,12 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
590591
PGG(num_links)++;
591592
PGG(num_persistent)++;
592593
} else { /* we do */
594+
if ((connect_type & PGSQL_CONNECT_FORCE_NEW)) {
595+
if (zend_hash_del(&EG(persistent_list), str.s) != SUCCESS) {
596+
goto err;
597+
}
598+
goto newpconn;
599+
}
593600
if (le->type != le_plink) {
594601
goto err;
595602
}

ext/pgsql/tests/gh13519.phpt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
GH-13519 - PGSQL_CONNECT_FORCE_NEW with persistent connections.
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php include("skipif.inc"); ?>
7+
--FILE--
8+
<?php
9+
include 'config.inc';
10+
11+
$db1 = pg_pconnect($conn_str);
12+
$pid1 = pg_get_pid($db1);
13+
for ($i = 0; $i < 3; $i ++) {
14+
$db2 = pg_pconnect($conn_str);
15+
var_dump($pid1 === pg_get_pid($db2));
16+
}
17+
for ($i = 0; $i < 3; $i ++) {
18+
$db2 = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW);
19+
var_dump($pid1 === pg_get_pid($db2));
20+
pg_close($db2);
21+
}
22+
pg_close($db1);
23+
?>
24+
--EXPECT--
25+
bool(true)
26+
bool(true)
27+
bool(true)
28+
bool(false)
29+
bool(false)
30+
bool(false)

0 commit comments

Comments
 (0)