《PHP編程:PHP sleep()函數, usleep()函數》要點:
本文介紹了PHP編程:PHP sleep()函數, usleep()函數,希望對您有用。如果有疑問,可以聯系我們。
PHP編程PHP sleep() 函數
PHP編程定義和用法
PHP編程sleep() 函數延遲代碼執行若干秒.
語法sleep(seconds)
seconds 必需.以秒計的暫停時間.
返回值
PHP編程若成功,返回 0,否則返回 false.
錯誤/異常
PHP編程如果指定的描述 seconds 是負數,該函數將生成一個 E_WARNING.
PHP編程例子
PHP編程
<?php
echo date('h:i:s') . "<br />"; //暫停 10 秒
sleep(10);//重新開始
echo date('h:i:s');
?>
PHP編程輸出:
PHP編程12:00:08 12:00:18
PHP編程
PHP usleep() 函數
PHP編程定義和用法
PHP編程usleep() 函數延遲代碼執行若干微秒.
語法usleep(microseconds)
microseconds 必需.以微秒計的暫停時間.
返回值
PHP編程無返回值.
提示和注釋
PHP編程注釋:在 PHP 5 之前,該函數無法工作于 Windows 系統上.
PHP編程注釋:一微秒等于百萬分之一秒.
例子
PHP編程
<?php
echo date('h:i:s') . "<br />";
//延遲 10 描述
usleep(10000000);
//再次開始
echo date('h:i:s');
?>
PHP編程輸出:
09:23:14 09:23:24
PHP編程PHP中sleep和unsleep的用法
PHP編程當你需要程序暫停執行幾秒可以用 sleep
PHP編程int sleep ( int $seconds ) 程序暫停$seconds秒后執行.
PHP編程Returns zero on success, or FALSE on error.成功返回0,錯誤返回false.
PHP編程If the call was interrupted by a signal, sleep() returns a non-zero value. On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
PHP編程如果調用被信號中斷,該函數返回一個非0值.在windows平臺上,這個值總是192(這個值是Windows API中等待IO完成WAIT_IO_COMPLETION的常量值).其它平臺返回值為sleep還沒有執行的秒數.
PHP編程If the specified number of seconds is negative, this function will generate a E_WARNING.
PHP編程如果參數為負值,則函數生產一個警告錯誤.
PHP編程當你需要程序暫停執行1秒一下時間的時候你可以用usleep
PHP編程void usleep ( int $micro_seconds )
PHP編程Delays program execution for the given number of micro seconds.
PHP編程usleep參數是微秒,且無返回值.
PHP編程當你需要程序執行單位更小(小于微秒)可以用
PHP編程time_nanosleep() - Delay for a number of seconds and nanoseconds
PHP編程如果你希望程序暫停執行到某個時間點,你可以用
PHP編程time_sleep_until()- Make the script sleep until the specified time
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/3985.html