PHPのset_time_limit,max_execution_time,sleep

2831 ワード

マニュアルの説明:
set_time_limit()
set_time_Limit-スクリプトの最大実行時間を設定します
説明
void 
set_time_limit ( 
int $seconds )
スクリプトの実行を許可する時間を秒単位で設定します.この設定を超えると、スクリプトは致命的なエラーを返します.デフォルト値は30秒、またはphpです.iniのmax_execution_timeが定義された値.この値が存在する場合.
この関数が呼び出されるとset_time_limit()はゼロからタイムアウトカウンタを再起動します.すなわち、タイムアウトのデフォルトが30秒である場合、スクリプトにはset_のような25秒が設定されています.time_limit(20).では、スクリプトはタイムアウト前に合計45秒実行できます.
パラメータ
seconds
最大実行時間(秒単位)0(ゼロ)に設定した場合、時間的な制限はありません.
戻り値
戻り値がありません.
コメント
Warning
phpがセキュリティモードで実行されている場合、この機能は有効になりません.安全モードをオフにするかphpを変更する以外は.iniの中の時間制限は、他に方法がありません.
Note:
set_time_limit()関数と構成命令max_execution_timeは、スクリプト自体が実行される時間にのみ影響します.システム()を使用するシステム呼び出し、ストリーム操作、データベース操作などのスクリプトが実行される最大時間は、スクリプトが実行されたときに含まれません.測定時間が実値のWindowsでは、そうではありません.
セーフモードでset_time_Limit()は役に立たない
max_execution_time
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.
The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.
You can not change this setting with ini_set()when running inセキュリティモード.The only workaround is to turn off safe mode or by changing the time limit in thephp.ini.
Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.
sleep()
sleep — Delay execution
説明
int 
sleep ( 
int $seconds )
Delays the program execution for the given number of seconds.
パラメータ
seconds
Halt time in seconds.
戻り値
Returns zero on success, or FALSE on error.
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 theWAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
エラー/例外
If the specified number of seconds is negative, this function will generate a E_WARNING.
更新ログ
バージョン#バージョン#
説明
5.3.4
Before PHP 5.3.4, on Windows, sleep() always returns NULL when sleep has occurred, regardless of whether the sleep was interrupted or not.
つまりset_time_limit()関数は、スクリプトが自分で実行する時間のみを計算し、system()を呼び出し、io操作、データベースクエリー、sleep()関数はスクリプト実行時間内に計算しない.
set_time_limit(20);  
for($i=0;$i<1000;$i++)                                                             
{  
      echo "i=$i
"; sleep(5); }