Skip to content

Commit 33bca97

Browse files
committed
Fix GH-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.
1 parent f732ab8 commit 33bca97

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

ext/pgsql/pgsql.c

Lines changed: 7 additions & 0 deletions
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));
@@ -620,6 +621,12 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
620621
pg_result = PQexec(pgsql, "RESET ALL;");
621622
PQclear(pg_result);
622623
}
624+
if ((connect_type & PGSQL_CONNECT_FORCE_NEW)) {
625+
if (zend_hash_del(&EG(persistent_list), str.s) != SUCCESS) {
626+
goto err;
627+
}
628+
goto newpconn;
629+
}
623630
}
624631

625632
object_init_ex(return_value, pgsql_link_ce);

ext/pgsql/tests/gh13519.phpt

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

0 commit comments

Comments
 (0)