PHP sleep()函數(shù), usleep()函數(shù)
PHP sleep() 函數(shù)
定義和用法
sleep() 函數(shù)延遲代碼執(zhí)行若干秒。
語法sleep(seconds)
seconds 必需。以秒計(jì)的暫停時(shí)間。
返回值
若成功,返回 0,否則返回 false。
錯誤/異常
如果指定的描述 seconds 是負(fù)數(shù),該函數(shù)將生成一個(gè) E_WARNING。
例子
<?php echo date('h:i:s') . "<br />"; //暫停 10 秒 sleep(10);//重新開始 echo date('h:i:s'); ?>
輸出:
12:00:08 12:00:18
PHP usleep() 函數(shù)
定義和用法
usleep() 函數(shù)延遲代碼執(zhí)行若干微秒。
語法usleep(microseconds)
microseconds 必需。以微秒計(jì)的暫停時(shí)間。
返回值
無返回值。
提示和注釋
注釋:在 PHP 5 之前,該函數(shù)無法工作于 Windows 系統(tǒng)上。
注釋:一微秒等于百萬分之一秒。
例子
<?php echo date('h:i:s') . "<br />"; //延遲 10 描述 usleep(10000000); //再次開始 echo date('h:i:s'); ?>
輸出:
09:23:14 09:23:24
PHP中sleep和unsleep的用法
當(dāng)你需要程序暫停執(zhí)行幾秒可以用 sleep
int sleep ( int $seconds ) 程序暫停$seconds秒后執(zhí)行。
Returns zero on success, or FALSE on error.成功返回0,錯誤返回false。
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.
如果調(diào)用被信號中斷,該函數(shù)返回一個(gè)非0值。在windows平臺上,這個(gè)值總是192(這個(gè)值是Windows API中等待IO完成WAIT_IO_COMPLETION的常量值)。其它平臺返回值為sleep還沒有執(zhí)行的秒數(shù)。
If the specified number of seconds is negative, this function will generate a E_WARNING.
如果參數(shù)為負(fù)值,則函數(shù)生產(chǎn)一個(gè)警告錯誤.
當(dāng)你需要程序暫停執(zhí)行1秒一下時(shí)間的時(shí)候你可以用usleep
void usleep ( int $micro_seconds )
Delays program execution for the given number of micro seconds.
usleep參數(shù)是微秒,且無返回值。
當(dāng)你需要程序執(zhí)行單位更小(小于微秒)可以用
time_nanosleep() - Delay for a number of seconds and nanoseconds
如果你希望程序暫停執(zhí)行到某個(gè)時(shí)間點(diǎn),你可以用
time_sleep_until()- Make the script sleep until the specified time
相關(guān)文章
echo, print, printf 和 sprintf 區(qū)別
echo, print, printf 和 sprintf 區(qū)別...2006-12-12php實(shí)現(xiàn)可運(yùn)算的驗(yàn)證碼
這篇文章主要介紹了php如何實(shí)現(xiàn)可運(yùn)算的驗(yàn)證碼,代碼很詳細(xì),值得大家學(xué),感興趣的小伙伴們可以參考一下2015-11-11spl_autoload_register與autoload的區(qū)別詳解
本篇文章是對spl_autoload_register與autoload的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php自定義函數(shù)實(shí)現(xiàn)二維數(shù)組排序功能
這篇文章主要介紹了php自定義函數(shù)實(shí)現(xiàn)二維數(shù)組排序功能,涉及php針對數(shù)組的判斷、遍歷、轉(zhuǎn)換、排序等相關(guān)操作技巧,需要的朋友可以參考下2016-07-07PHP頁面靜態(tài)化——純靜態(tài)與偽靜態(tài)用法詳解
這篇文章主要介紹了PHP頁面靜態(tài)化——純靜態(tài)與偽靜態(tài)用法,結(jié)合實(shí)例形式分析了PHP頁面靜態(tài)化——純靜態(tài)與偽靜態(tài)相關(guān)原理、實(shí)現(xiàn)方法與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-06-06php封裝的數(shù)據(jù)庫函數(shù)與用法示例【參考thinkPHP】
這篇文章主要介紹了php封裝的數(shù)據(jù)庫函數(shù)與用法,基于thinkPHP中數(shù)據(jù)庫操作相關(guān)代碼整理簡化而來,包括針對數(shù)據(jù)庫的設(shè)置、連接、查詢及日志操作等功能,簡單實(shí)用,需要的朋友可以參考下2016-11-11