set_time_limit

void set_time_limit設定允許腳本運行的時間,單位為秒。如果超過了此設定,腳本返回一個致命的錯誤。默認值為30秒,或者是在php.ini的max_execution_time被定義的值,如果此值存在。

函式說明,函式定義,注釋說明,警告,注意,實例說明,例-1,例-2,

函式說明

(PHP 4中,PHP 5中)
set_time_limit - 限制最大的執行時間

函式定義

當此函式被調用時,set_time_limit()會從零開始重新啟動逾時計數器。換句話說,如果逾時默認是30秒,在腳本運行了了25秒時調用 set_time_limit(20),那么,腳本在逾時之前可運行總時間為45秒。
參數
參數
描述
$seconds
為整型,最大執行時間,以秒計。如果設定為零,沒有時間方面的限制。
返回值
沒有返回值。

注釋說明

警告

當PHP運行在安全模式下時此函式無效。除了關閉安全模式或者在php.ini程式中修改最大運行時間沒有其他辦法讓此函式運行。
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

注意

set_time_limit()函式和配置指令max_execution_time只影響腳本本身執行的時間。任何發生在諸如使用 system()的系統調用,流操作,資料庫操作等的腳本執行的最大時間不包括其中,當該腳本已運行。在測量時間是實值的Windows中,情況就不是如此了。
The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

實例說明

例-1

如果沒有打開安全模式,設定程式運行時間為25秒。例如:
<?php
if( !ini_get('safe_mode') ){

相關詞條

熱門詞條

聯絡我們