PHP sleep()函數(shù), usleep()函數(shù)
PHP sleep() 函數(shù)
定義和用法
sleep() 函數(shù)延遲代碼執(zhí)行若干秒。
語法sleep(seconds)
seconds 必需。以秒計的暫停時間。
返回值
若成功,返回 0,否則返回 false。
錯誤/異常
如果指定的描述 seconds 是負數(shù),該函數(shù)將生成一個 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 必需。以微秒計的暫停時間。
返回值
無返回值。
提示和注釋
注釋:在 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的用法
當你需要程序暫停執(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ù)返回一個非0值。在windows平臺上,這個值總是192(這個值是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ù)為負值,則函數(shù)生產(chǎn)一個警告錯誤.
當你需要程序暫停執(zhí)行1秒一下時間的時候你可以用usleep
void usleep ( int $micro_seconds )
Delays program execution for the given number of micro seconds.
usleep參數(shù)是微秒,且無返回值。
當你需要程序執(zhí)行單位更小(小于微秒)可以用
time_nanosleep() - Delay for a number of seconds and nanoseconds
如果你希望程序暫停執(zhí)行到某個時間點,你可以用
time_sleep_until()- Make the script sleep until the specified time
相關(guān)文章
CentOS7系統(tǒng)搭建LAMP及更新PHP版本操作詳解
這篇文章主要介紹了CentOS7系統(tǒng)搭建LAMP及更新PHP版本操作,總結(jié)分析了CentOS7系統(tǒng)搭建LAMP及更新PHP版本操作相關(guān)原理、步驟、操作命令與注意事項,需要的朋友可以參考下2020-03-03
PHP 雜談《重構(gòu)-改善既有代碼的設(shè)計》之三 重新組織數(shù)據(jù)
承接上文的PHP 雜談《重構(gòu)-改善既有代碼的設(shè)計》之 重新組織你的函數(shù)繼續(xù)重構(gòu)方面的內(nèi)容2012-04-04
PHP使用pdo連接access數(shù)據(jù)庫并循環(huán)顯示數(shù)據(jù)操作示例
這篇文章主要介紹了PHP使用pdo連接access數(shù)據(jù)庫并循環(huán)顯示數(shù)據(jù)操作,結(jié)合實例形式較為詳細的分析了php使用pdo進行access數(shù)據(jù)庫連接、查詢、執(zhí)行sql語句、預處理等相關(guān)操作技巧與注意事項,需要的朋友可以參考下2018-06-06
PHP實現(xiàn)動態(tài)執(zhí)行代碼的方法
這篇文章主要介紹了PHP實現(xiàn)動態(tài)執(zhí)行代碼的方法,涉及PHP中create_function函數(shù)的使用技巧,需要的朋友可以參考下2016-03-03
PHPExcel導出Excel報錯:PHPExcel_IOFactory::load()的解決方案
這篇文章主要介紹了PHPExcel導出Excel報錯:PHPExcel_IOFactory::load()的解決方案,文中有詳細的問題分析和解決方法供大家參考,具有一定的參考價值,需要的朋友可以參考下2023-11-11

