$t = 3;
-function busy_sleep($how_long)
+function busy_wait($how_long)
{
- $now = time();
+ $until = time() + $how_long;
- while($now + $how_long > time());
+ while ($until > time());
}
--TEST--
Timeout within while loop
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+$t = 3;
set_time_limit($t);
-while(1) {
- echo 1;
- busy_sleep(1);
+while (1) {
+ busy_wait(1);
}
?>
never reached here
--EXPECTF--
-111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
--TEST--
Timeout within function
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function hello ($t) {
echo "call";
- busy_sleep($t*2);
+ busy_wait($t*2);
}
hello($t);
--TEST--
Timeout within shutdown function, variation
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function f()
{
echo "call";
- busy_sleep(4);
+ busy_wait(4);
}
register_shutdown_function("f");
--TEST--
Timeout within array_walk
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function cb(&$i, $k, $p)
{
- echo 1;
- busy_sleep(1);
+ busy_wait(1);
}
$a = array(1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1);
?>
never reached here
--EXPECTF--
-111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
--TEST--
Timeout within eval
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function hello ($t) {
echo "call", PHP_EOL;
- busy_sleep($t*2);
+ busy_wait($t*2);
}
eval('hello($t);');
--TEST--
Timeout within call_user_func
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function hello ($t) {
echo "call", PHP_EOL;
- busy_sleep($t*2);
+ busy_wait($t*2);
}
call_user_func('hello', $t);
--TEST--
Timeout within function containing exteption
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function f($t) {
echo "call";
- busy_sleep($t*2);
+ busy_wait($t*2);
throw new Exception("never reached here");
}
--TEST--
Timeout within function trowing exteption before timeout reached
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function f($t) {
echo "call";
- busy_sleep($t-1);
+ busy_wait($t-1);
throw new Exception("exception before timeout");
}
--TEST--
Timeout within for loop
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
$t = 3;
set_time_limit($t);
-for($i = 0; $i < 42; $i++) {
- echo 1;
- busy_sleep(1);
+for ($i = 0; $i < 42; $i++) {
+ busy_wait(1);
}
?>
never reached here
--EXPECTF--
-111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
--TEST--
Timeout within foreach loop
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
+$t = 3;
include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
-$t = 3;
set_time_limit($t);
-foreach(range(0, 42) as $i) {
- echo 1;
- busy_sleep(1);
+foreach (range(0, 42) as $i) {
+ busy_wait(1);
}
?>
never reached here
--EXPECTF--
-111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
--TEST--
Timeout within shutdown function
+--SKIPIF--
+<?php
+ if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
--FILE--
<?php
function f()
{
echo "call";
- busy_sleep(4);
+ busy_wait(4);
}
register_shutdown_function("f");