Home  >  Article  >  php教程  >  php set_time_limit()设置页面执行时间

php set_time_limit()设置页面执行时间

PHP中文网
PHP中文网Original
2017-03-21 15:03:022313browse

set_time_limit函数可以临时定义你当前页面的执行时间,set_time_limit(0)时页面就永远有效直到程序执行完毕了,下面我来介绍set_time_limit用法.

语法 : void set_time_limit (int seconds)

注意 : 当PHP是执行在安全模式时,set_time_limit( )将不会有结果,除非是关闭安全模式或是修改结构档案中(在PHP3中叫做php3.ini,在PHP4则叫做php.ini)的时间限制.

实例代码如下:

<?php
set_time_limit(1000) 
?>

当此函数被调用时, set_time_limit()会从零开始重新启动超时计数器.换句话说,如果超时默认是30秒,在脚本运行了了25秒时调用 set_time_limit(20),那么,脚本在超时之前可运行总时间为45秒.

实例代码如下:

<?php 
require_once(&#39;db.php&#39;); 
$stmt = $db->query($sql); 
while ($row = $stmt->fetchRow()) { 
    set_time_limit(0); 
    // your code here 
} 
?>

相关文章:

php页面最大执行时间 set_time_limit函数不起作用

php set_time_limit(0) 设置程序执行时间的函数

set_time_limit — 设置脚本最大执行时间

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn