sleep_basic.phpt 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test sleep() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. if (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. echo "*** Testing sleep() : basic functionality ***\n";
  14. $sleeptime = 5; // sleep for 5 seconds
  15. set_time_limit(20);
  16. $time_start = microtime(true);
  17. // Sleep for a while
  18. sleep($sleeptime);
  19. // Test passes if sleeps for at least 98% of specified time
  20. $sleeplow = $sleeptime - ($sleeptime * 2 /100);
  21. $time_end = microtime(true);
  22. $time = $time_end - $time_start;
  23. echo "Thread slept for " . $time . " seconds\n";
  24. if ($time >= $sleeplow) {
  25. echo "TEST PASSED\n";
  26. } else {
  27. echo "TEST FAILED - time is ${time} secs and sleep was ${sleeptime} secs\n";
  28. }
  29. ?>
  30. ===DONE===
  31. --EXPECTF--
  32. *** Testing sleep() : basic functionality ***
  33. Thread slept for %f seconds
  34. TEST PASSED
  35. ===DONE===