1--TEST-- 2Test sleep() function : basic functionality 3--SKIPIF-- 4<?php 5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 6?> 7--FILE-- 8<?php 9/* Prototype : int sleep ( int $seconds ) 10 * Description: Delays the program execution for the given number of seconds . 11 * Source code: ext/standard/basic_functions.c 12 */ 13 14echo "*** Testing sleep() : basic functionality ***\n"; 15 16$sleeptime = 1; // sleep for 1 seconds 17 18set_time_limit(20); 19 20$time_start = microtime(true); 21 22// Sleep for a while 23sleep($sleeptime); 24 25// Test passes if sleeps for at least 98% of specified time 26$sleeplow = $sleeptime - ($sleeptime * 2 /100); 27 28$time_end = microtime(true); 29$time = $time_end - $time_start; 30 31echo "Thread slept for " . $time . " seconds\n"; 32 33if ($time >= $sleeplow) { 34 echo "TEST PASSED\n"; 35} else { 36 echo "TEST FAILED - time is ${time} secs and sleep was ${sleeptime} secs\n"; 37} 38?> 39===DONE=== 40--EXPECTF-- 41*** Testing sleep() : basic functionality *** 42Thread slept for %f seconds 43TEST PASSED 44===DONE=== 45