1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-13519: another attempt after the faulty fix.

Close GH-14055
This commit is contained in:
David Carlier
2024-04-27 07:56:09 +01:00
parent 8e4363de55
commit 243827b83f
3 changed files with 45 additions and 0 deletions

2
NEWS
View File

@@ -174,6 +174,8 @@ PHP NEWS
- PGSQL:
. Added the possibility to have no conditions for pg_select. (OmarEmaraDev)
. Persistent connections support the PGSQL_CONNECT_FORCE_RENEW flag.
(David Carlier)
- Phar:
. Fixed bug GH-12532 (PharData created from zip has incorrect timestamp).

View File

@@ -560,6 +560,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
/* try to find if we already have this link in our persistent list */
if ((le = zend_hash_find_ptr(&EG(persistent_list), str.s)) == NULL) { /* we don't */
newpconn:
if (PGG(max_links) != -1 && PGG(num_links) >= PGG(max_links)) {
php_error_docref(NULL, E_WARNING,
"Cannot create new link. Too many open links (" ZEND_LONG_FMT ")", PGG(num_links));
@@ -591,6 +592,18 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (le->type != le_plink) {
goto err;
}
if (connect_type & PGSQL_CONNECT_FORCE_NEW) {
PGresult *pg_result;
while ((pg_result = PQgetResult(le->ptr))) {
PQclear(pg_result);
}
PQfinish(le->ptr);
le->ptr = NULL;
PGG(num_links)--;
PGG(num_persistent)--;
goto newpconn;
}
/* ensure that the link did not die */
if (PGG(auto_reset_persistent) & 1) {
/* need to send & get something from backend to

View File

@@ -0,0 +1,30 @@
--TEST--
GH-13519 - PGSQL_CONNECT_FORCE_NEW with persistent connections.
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include 'inc/config.inc';
$db1 = pg_pconnect($conn_str);
$pid1 = pg_get_pid($db1);
for ($i = 0; $i < 3; $i ++) {
$db2 = pg_pconnect($conn_str);
var_dump($pid1 === pg_get_pid($db2));
}
for ($i = 0; $i < 3; $i ++) {
$db2 = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW);
var_dump($pid1 === pg_get_pid($db2));
pg_close($db2);
}
pg_close($db1);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)