Skip to content

Commit c0ba573

Browse files
committed
Merge branch 'PHP-8.3'
2 parents dce6ed3 + 12f5236 commit c0ba573

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
@@ -560,6 +560,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
560560

561561
/* try to find if we already have this link in our persistent list */
562562
if ((le = zend_hash_find_ptr(&EG(persistent_list), str.s)) == NULL) { /* we don't */
563+
newpconn:
563564
if (PGG(max_links) != -1 && PGG(num_links) >= PGG(max_links)) {
564565
php_error_docref(NULL, E_WARNING,
565566
"Cannot create new link. Too many open links (" ZEND_LONG_FMT ")", PGG(num_links));
@@ -588,6 +589,12 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
588589
PGG(num_links)++;
589590
PGG(num_persistent)++;
590591
} else { /* we do */
592+
if ((connect_type & PGSQL_CONNECT_FORCE_NEW)) {
593+
if (zend_hash_del(&EG(persistent_list), str.s) != SUCCESS) {
594+
goto err;
595+
}
596+
goto newpconn;
597+
}
591598
if (le->type != le_plink) {
592599
goto err;
593600
}

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)