Skip to content

Commit 49b0f07

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.
1 parent f732ab8 commit 49b0f07

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-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: 30 additions & 0 deletions
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)