Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: time_nanosleep - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

time_sleep_until" width="11" height="7"/> <sys_getloadavg
Last updated: Sun, 25 Nov 2007

view this page in

time_nanosleep

(PHP 5)

time_nanosleep — 秒およびナノ秒単位で実行を遅延する

説明

mixed time_nanosleep ( int $seconds , int $nanoseconds )

指定した seconds および nanoseconds の時間だけプログラムの実行を遅延させます。

パラメータ

seconds

正の整数である必要があります。

nanoseconds

十億よりも小さい正の整数である必要があります。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

シグナルによって遅延処理が中断された場合、以下の要素からなる連想配列を返します。

  • seconds - 残りの秒数
  • nanoseconds - 残りのナノ秒数

Example#1 time_nanosleep() の例

<?php
// 注意! もし配列が返された場合、これはうまく動作しません
if (time_nanosleep(0500000000)) {
    echo 
"0.5 秒遅延しました。\n";
}

// こちらのほうがよいでしょう
if (time_nanosleep(0500000000) === true) {
    echo 
"0.5 秒遅延しました。\n";
}

// そしてこれが最良の方法です
$nano time_nanosleep(2100000);

if (
$nano === true) {
    echo 
"2.1 秒遅延しました。\n";
} elseif (
$nano === false) {
    echo 
"遅延に失敗しました。\n";
} elseif (
is_array($nano)) {
    
$seconds $nano['seconds'];
    
$nanoseconds $nano['nanoseconds'];
    echo 
"シグナルによって中断しました。\n";
    echo 
"残りの秒数は $seconds 秒と $nanoseconds ナノ秒です。";
}
?>

注意

注意: この関数は Windows 環境にはまだ実装されていません。



time_sleep_until" width="11" height="7"/> <sys_getloadavg
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
time_nanosleep
fantasysportswire at yahoo dot com
19-Dec-2006 08:27
Just glancing at this - and the note from over a year ago with a implementation for windows.. with 5.0.0 and higher it would be simplier to just do something like......

<?

if (!function_exists('time_nanosleep')) {

function
time_nanosleep($seconds, $nanoseconds) {

sleep($seconds);
usleep(round($nanoseconds/100));

return
true;

}

}

?>

....off the top of my head - obviously simple enough there should be no mistakes.. but those are the ones that always seem to get ya :( .....
anybody (a) emuxperts.net
22-Aug-2006 08:03
Documentation states that "seconds" must be positive. This is not correct, 0 is possible.

Rather, "seconds" must be non-negative.
m at kufi dot net
14-Aug-2005 06:03
You should take into account, if you use the function replacement down here, the CPU will be in use of 99% for the time of execution...

(A little bit better in this situation is to let the 'full seconds' go by a normal sleep command (makes the thread sleep!, and uses minimum cpu))

<?php
   
//THIS IS THE FUNCTION WE ARE TALKIN ABOUT
   
function timeWait($microtime)
    {
//optimizations added by me [start]
//sleep the full seconds
sleep(intval($microtime));
//set the microtime to only resleep the last part of the nanos
$microtime = $microtime - intval($microtime);
//optimizations added by me [end]

       
$timeLimit = $microtime + array_sum(explode(" ",microtime()));
        while(
array_sum(explode(" ",microtime())) < $timeLimit)
        {
/*DO NOTHING*/}
        return(
true);
    }
 
   
//THIS IS HOW WE CAN USE IT
   
echo "Process started at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds.<br>";
   
timeWait(5.5); //With this call the system will wait 5 seconds and a half. You can use either integer or float.
   
echo "Process completed at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds.";
 
?>
tecnomaniac at ig dot com dot br
27-Jul-2005 07:04
This is an alternative function to sleep_nanosecond that you can use with PHP versions below PHP 5.0. It is not very accurate if we talk about nanoseconds but the results are satisfatory. Enjoy!

<?php
   
//THIS IS THE FUNCTION WE ARE TALKIN ABOUT
   
function timeWait($microtime)
    {
       
$timeLimit = $microtime + array_sum(explode(" ",microtime()));
        while(
array_sum(explode(" ",microtime())) < $timeLimit)
        {
/*DO NOTHING*/}
        return(
true);
    }

   
//THIS IS HOW WE CAN USE IT
   
echo "Process started at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds.<br>";
   
timeWait(5.5); //With this call the system will wait 5 seconds and a half. You can use either integer or float.
   
echo "Process completed at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds.";
?>

time_sleep_until" width="11" height="7"/> <sys_getloadavg
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites