[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Weilin Du | Date: | Fri, 23 Oct 2026 16:50:59 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142630@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-10-24T00:39:50+08:00
Commit: https://github.com/php/php-src/commit/48786b4dc10c3512ce84c19d028325028c3b0b00
Raw diff: https://github.com/php/php-src/commit/48786b4dc10c3512ce84c19d028325028c3b0b00.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Fix GH-24308: Preserve syslog handles not opened by PHP (#24310)
Changed paths:
A ext/standard/tests/network/gh24308.phpt
M NEWS
M ext/standard/syslog.c
Diff:
diff --git a/NEWS b/NEWS
index 0b0450074b18..cedad8181808 100644
--- a/NEWS
+++ b/NEWS
@@ -113,6 +113,8 @@ PHP NEWS
file fails after it was already truncated. (Ilia Alshanetsky)
- Standard:
+ . Fixed bug GH-24308 (Request shutdown calls closelog() even when syslog
+ was not opened by PHP). (lazerg)
. Fixed password_get_info() and password_needs_rehash() accepting malformed
bcrypt costs. (Ilia Alshanetsky)
. Fixed proc_open() null descriptor not being inheritable on Windows.
diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c
index c5d73eb008ec..37aab54c569d 100644
--- a/ext/standard/syslog.c
+++ b/ext/standard/syslog.c
@@ -41,7 +41,9 @@ PHP_MINIT_FUNCTION(syslog)
PHP_RSHUTDOWN_FUNCTION(syslog)
{
- php_closelog();
+ if (PG(have_called_openlog)) {
+ php_closelog();
+ }
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
@@ -102,6 +104,9 @@ PHP_FUNCTION(syslog)
Z_PARAM_STR(message)
ZEND_PARSE_PARAMETERS_END();
+ if (!PG(have_called_openlog)) {
+ php_openlog(PG(syslog_ident), 0, PG(syslog_facility));
+ }
php_syslog_str(priority, message);
RETURN_TRUE;
}
diff --git a/ext/standard/tests/network/gh24308.phpt b/ext/standard/tests/network/gh24308.phpt
new file mode 100644
index 000000000000..bfb50ae95e40
--- /dev/null
+++ b/ext/standard/tests/network/gh24308.phpt
@@ -0,0 +1,44 @@
+--TEST--
+GH-24308 (syslog() without openlog() is closed at request end)
+--SKIPIF--
+<?php
+if (PHP_OS_FAMILY !== 'Linux') die('skip Linux only');
+if (!@is_dir('/proc/self/fd')) die('skip requires /proc/self/fd');
+if (!@stream_socket_client('udg:///dev/log')) die('skip requires /dev/log');
+?>
+--FILE--
+<?php
+$serverCode = <<<'CODE'
+function sockets() {
+ $sockets = [];
+ foreach (scandir('/proc/self/fd') as $fd) {
+ $link = @readlink("/proc/self/fd/$fd");
+ if ($link !== false && str_starts_with($link, 'socket:')) {
+ $sockets[$fd] = $link;
+ }
+ }
+ return $sockets;
+}
+
+if (isset($_GET['syslog'])) {
+ $before = sockets();
+ syslog(LOG_DEBUG, 'GH-24308');
+ echo json_encode(array_diff_assoc(sockets(), $before));
+} else {
+ echo json_encode(sockets());
+}
+CODE;
+
+include __DIR__."/../../../../sapi/cli/tests/php_cli_server.inc";
+php_cli_server_start($serverCode, null, []);
+
+$opened = json_decode(file_get_contents("http://" .
PHP_CLI_SERVER_ADDRESS . "/?syslog"), true);
+var_dump(count($opened));
+
+$next = json_decode(file_get_contents("http://" .
PHP_CLI_SERVER_ADDRESS . "/"), true);
+var_dump(array_intersect_assoc($opened, $next));
+?>
+--EXPECT--
+int(1)
+array(0) {
+}