From bda37c11618b84ed267835d48c7c8adeddf1db06 Mon Sep 17 00:00:00 2001 From: Sujan Miya Date: Mon, 3 Nov 2025 20:30:52 +0600 Subject: [PATCH 1/3] [skip ci] Fix typo in CODING_STANDARDS.md (GH-20364) --- CODING_STANDARDS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index c599194ed50e3..47b76717c8391 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -276,7 +276,7 @@ rewritten to comply with these rules. 1. The length of constant string literals should be calculated via ``strlen()`` instead of using ``sizeof()-1`` as it is clearer and any modern compiler - will optimize it away. Legacy usages of the latter style exists within the + will optimize it away. Legacy usages of the latter style exist within the codebase but should not be refactored, unless larger refactoring around that code is taking place. From 540fd6e96bb12a466cb0e4ea4696fd1ad618ef7f Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+ndossche@users.noreply.github.com> Date: Mon, 3 Nov 2025 18:46:56 +0100 Subject: [PATCH 2/3] dom: Optimize splitText() (#20371) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids duplicating the intermediate strings, by transferring ownership. It's hard to measure the improvement in a reliable way, as we have to operate on the same node. The following benchmark shows a nice improvement (although not perfect as a benchmark): ```php loadXML('testabcdef'); $text = $dom->documentElement->firstChild; for ($i = 0; $i < 1000000; $i++) { $text2 = clone $text; $text2->splitText(5); } ``` Only tested on my desktop i7-4790: ``` Benchmark 1: ./sapi/cli/php x.php Time (mean ± σ): 284.1 ms ± 2.8 ms [User: 280.0 ms, System: 3.0 ms] Range (min … max): 281.4 ms … 291.3 ms 10 runs Benchmark 2: ./sapi/cli/php_old x.php Time (mean ± σ): 314.0 ms ± 7.8 ms [User: 309.2 ms, System: 2.9 ms] Range (min … max): 306.5 ms … 328.0 ms 10 runs Summary ./sapi/cli/php x.php ran 1.11 ± 0.03 times faster than ./sapi/cli/php_old x.php ``` --- UPGRADING | 3 +++ ext/dom/text.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/UPGRADING b/UPGRADING index f4a455caefa1f..7a3aff95da8ef 100644 --- a/UPGRADING +++ b/UPGRADING @@ -117,5 +117,8 @@ PHP 8.6 UPGRADE NOTES . Arguments are now passed more efficiently to known constructors (e.g. when using new self()). +- DOM: + . Made splitText() faster and consume less memory. + - JSON: . Improve performance of encoding arrays and objects. diff --git a/ext/dom/text.c b/ext/dom/text.c index b08619252b850..4c503201c8bfe 100644 --- a/ext/dom/text.c +++ b/ext/dom/text.c @@ -127,17 +127,18 @@ PHP_METHOD(DOMText, splitText) first = xmlUTF8Strndup(cur, (int)offset); second = xmlUTF8Strsub(cur, (int)offset, (int)(length - offset)); - xmlNodeSetContent(node, first); - nnode = xmlNewDocText(node->doc, second); - - xmlFree(first); - xmlFree(second); + xmlNodeSetContent(node, NULL); + node->content = first; + nnode = xmlNewDocText(node->doc, NULL); if (nnode == NULL) { + xmlFree(second); php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true); RETURN_THROWS(); } + nnode->content = second; + if (node->parent != NULL) { nnode->type = XML_ELEMENT_NODE; xmlAddNextSibling(node, nnode); From 2d105afce7d66cb42cbfd3226a35879548eabbd8 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Mon, 3 Nov 2025 19:12:09 +0100 Subject: [PATCH 3/3] socket: properly expose TCP keepalive constants (#20376) This fixes missing constants on MacOS where TCP_KEEPALIVE, TCP_KEEPINTVL and TCP_KEEPCNT are available. Currently only TCP_KEEPALIVE is defined there. --- ext/sockets/sockets.stub.php | 4 ++ ext/sockets/sockets_arginfo.h | 6 ++- ext/sockets/tests/socket_tcp_keepalive.phpt | 52 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ext/sockets/tests/socket_tcp_keepalive.phpt diff --git a/ext/sockets/sockets.stub.php b/ext/sockets/sockets.stub.php index 6050a89414565..3df9b598a1e8f 100644 --- a/ext/sockets/sockets.stub.php +++ b/ext/sockets/sockets.stub.php @@ -643,11 +643,15 @@ * @cvalue TCP_KEEPIDLE */ const TCP_KEEPIDLE = UNKNOWN; +#endif +#ifdef TCP_KEEPINTVL /** * @var int * @cvalue TCP_KEEPINTVL */ const TCP_KEEPINTVL = UNKNOWN; +#endif +#ifdef TCP_KEEPCNT /** * @var int * @cvalue TCP_KEEPCNT diff --git a/ext/sockets/sockets_arginfo.h b/ext/sockets/sockets_arginfo.h index b7af6eb6b89ac..edfc344ff8cc0 100644 --- a/ext/sockets/sockets_arginfo.h +++ b/ext/sockets/sockets_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7b1baf47dce2fb08faa5616068238ea078d1609b */ + * Stub hash: f754368e28f6e45bf3a63a403e49f5659c29d2c6 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1) @@ -544,7 +544,11 @@ static void register_sockets_symbols(int module_number) #endif #if defined(TCP_KEEPIDLE) REGISTER_LONG_CONSTANT("TCP_KEEPIDLE", TCP_KEEPIDLE, CONST_PERSISTENT); +#endif +#if defined(TCP_KEEPINTVL) REGISTER_LONG_CONSTANT("TCP_KEEPINTVL", TCP_KEEPINTVL, CONST_PERSISTENT); +#endif +#if defined(TCP_KEEPCNT) REGISTER_LONG_CONSTANT("TCP_KEEPCNT", TCP_KEEPCNT, CONST_PERSISTENT); #endif #if defined(TCP_FUNCTION_BLK) diff --git a/ext/sockets/tests/socket_tcp_keepalive.phpt b/ext/sockets/tests/socket_tcp_keepalive.phpt new file mode 100644 index 0000000000000..cef570dc62b2b --- /dev/null +++ b/ext/sockets/tests/socket_tcp_keepalive.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test SO_KEEPALIVE and TCP keepalive constants +--EXTENSIONS-- +sockets +--SKIPIF-- + +--FILE-- + +--EXPECT-- +SO_KEEPALIVE: enabled +TCP_KEEPIDLE: 60 +TCP_KEEPINTVL: 10 +TCP_KEEPCNT: 5