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