Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Miscellaneous Functions : time_sleep_until

time_sleep_until

Make the script sleep until the specified time (PHP 5 >= 5.1.0)
bool time_sleep_until ( float timestamp )

Example 1365. A time_sleep_until() example

<?php

//returns false and generates a warning
var_dump(time_sleep_until(time()-1));

// may only work on faster computers, will sleep up to 0.2 seconds
var_dump(time_sleep_until(time()+0.2));

?>

Code Examples / Notes » time_sleep_until

ssnoyes

Implementation for < 5.1 or Windows users
<?php
if (!function_exists('time_sleep_until')) {
function time_sleep_until($future) {
if ($future < time()) {
trigger_error("Time in past", E_USER_WARNING);
return false;
}
sleep($future - time());
return true;
}
}
?>


roberto

better implementation
<?php
if (!function_exists('time_sleep_until')) {
  function time_sleep_until($future) {
      if ($future < time()) {
          trigger_error("Time in past", E_USER_WARNING);
          return false;
      }
      usleep(($future - microtime(1))*1000000);
      return true;
  }
}
?>


Change Language


Follow Navioo On Twitter
connection_aborted
connection_status
connection_timeout
constant
define
defined
die
eval
exit
get_browser
__halt_compiler
highlight_file
highlight_string
ignore_user_abort
pack
php_check_syntax
php_strip_whitespace
show_source
sleep
sys_getloadavg
time_nanosleep
time_sleep_until
uniqid
unpack
usleep
eXTReMe Tracker