summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Dowad <alexinbeijing@gmail.com>2020-05-06 22:02:57 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-05-13 12:47:12 +0200
commit555489dd83132d9c8ba28ad9cde1edf4c5823358 (patch)
tree6c4be86b04b34cf2e161a499505c12c545465a09 /tests
parentf06f260292f77d49f0d1fd7bedc6e8f5dac51137 (diff)
downloadphp-git-555489dd83132d9c8ba28ad9cde1edf4c5823358.tar.gz
Honor script time limit when calling shutdown functions
A time limit can be set on PHP script execution via `set_time_limit` (or .ini file). When the time limit is reached, the OS will notify PHP and `timed_out` and `vm_interrupt` flags are set. While these flags are regularly checked when executing PHP code, once the end of the script is reached, they are not checked while invoking shutdown functions (registered via `register_shutdown_function`). Of course, if the shutdown functions are implemented *in* PHP, then the interrupt flag will be checked while the VM is running PHP bytecode and the timeout will take effect. But if the shutdown functions are built-in (implemented in C), it will not. Since the shutdown functions are invoked through `zend_call_function`, add a check of the `vm_interrupt` flag there. Then, the script time limit will be respected when *entering* each shutdown function. The fact still remains that if a shutdown function is built-in and runs for a long time, script execution will not time out until it finishes and the interpreter tries to invoke the next one. Still, the behavior of scripts with execution time limits will be more consistent after this patch. To make the execution time-out feature work even more precisely, it would be necessary to scrutinize all the built-in functions and add checks of the `vm_interrupt` flag in any which can run for a long time. That might not be worth the effort, though. It should be mentioned that this patch does not solely affect shutdown functions, neither does it solely allow for interruption of running code due to script execution timeout. Anything else which causes `vm_interrupt` to be set, such as the PHP interpreter receiving a signal, will take effect when exiting from an internal function. And not just internal functions which are called because they were registered to run at shutdown; there are other cases where a series of internal functions might run in the midst of a script. In all such cases, it will be possible to interrupt the interpreter now. Closes GH-5543.
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/timeout_variation_10.phpt3
-rw-r--r--tests/basic/timeout_variation_9.phpt2
2 files changed, 1 insertions, 4 deletions
diff --git a/tests/basic/timeout_variation_10.phpt b/tests/basic/timeout_variation_10.phpt
index b067238db5..7680c96adf 100644
--- a/tests/basic/timeout_variation_10.phpt
+++ b/tests/basic/timeout_variation_10.phpt
@@ -5,8 +5,6 @@ Timeout within shutdown function, variation
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
---XFAIL--
-Missing timeout check in call_user_function
--FILE--
<?php
@@ -19,4 +17,5 @@ register_shutdown_function("sleep", 1);
shutdown happens after here
--EXPECTF--
shutdown happens after here
+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_9.phpt b/tests/basic/timeout_variation_9.phpt
index e59ae242dc..d645ef2bbf 100644
--- a/tests/basic/timeout_variation_9.phpt
+++ b/tests/basic/timeout_variation_9.phpt
@@ -5,8 +5,6 @@ Timeout within shutdown function
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
---XFAIL--
-Missing timeout check in call_user_function
--FILE--
<?php