Skip to content

Commit 299c3ba

Browse files
committed
Fix max_execution_time with cli-server router script
When the cli-server specifies a router script, we run it using zend_execute_scripts instead of php_execute_script, because the former preserves the return value of the script. However, php_execute_script also starts resets the execution timer with the value from max_execution_time. If the timer has previously been initialized with max_input_time, it will never be reset, and thus trigger at the incorrect time. Closes GH-12886
1 parent de3c5c0 commit 299c3ba

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.15
44

5+
- Cli:
6+
. Fix incorrect timeout in built-in web server when using router script and
7+
max_input_time. (ilutov)
8+
59
21 Dec 2023, PHP 8.2.14
610

711
- Core:

sapi/cli/php_cli_server.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,17 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
22402240
zend_try {
22412241
zval retval;
22422242

2243+
/* Normally php_execute_script restarts the timer with max_execution_time if it has
2244+
* previously been initialized with max_input_time. We're not using php_execute_script here
2245+
* because it does not provide a way to get the return value of the main script, so we need
2246+
* to restart the timer manually. */
2247+
if (PG(max_input_time) != -1) {
2248+
#ifdef PHP_WIN32
2249+
zend_unset_timeout();
2250+
#endif
2251+
zend_set_timeout(INI_INT("max_execution_time"), 0);
2252+
}
2253+
22432254
ZVAL_UNDEF(&retval);
22442255
if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE, &retval, 1, &zfd)) {
22452256
if (Z_TYPE(retval) != IS_UNDEF) {

0 commit comments

Comments
 (0)