两种模式“set_time_limit(5)”和“ini_set('max_execution_time','5')”重置时间,一个实用而明确的例子:
//-----------------------------------------------------------
//test "max_execution_time":
ini_set('max_execution_time', 5);
for ($i=0; $i<3; $i++) {
sleep(1);
}
ini_set('max_execution_time', 5);
for ($i=0; $i<3; $i++) {
sleep(1);
}
echo '
';
echo 'done with max_execution_time';
//-----------------------------------------------------------
//test "set_time_limit":
set_time_limit(5);
for ($i=0; $i<3; $i++) {
sleep(1);
}
set_time_limit(5);
for ($i=0; $i<3; $i++) {
sleep(1);
}
echo '
';
echo 'done with set_time_limit';
所有“for”成功完成,这表示在所有情况下都重置了时间,问候
该代码仅适用于Windows。 php linux中的休眠时间不会占用执行时间,例如在linux中:
set_time_limit(2);
for($i=0; $i<10; $i++)
{
echo ("$i \n");
sleep(1);
}
`会显示
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
但是在Windows上使用默认配置的相同代码将显示
1 | 2