Home  >  Article  >  Backend Development  >  php set_time_limit(0) 设置程序执行时间的函数_php技巧

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

WBOY
WBOYOriginal
2016-05-17 09:25:081136browse

set_time_limit(0);

括号里边的数字是执行时间,如果为零说明永久执行直到程序结束,如果为大于零的数字,则不管程序是否执行完成,到了设定的秒数,程序结束。

一个简单的例子,在网页里显示1500条语句,如果未设置失效时间,则程序执行到791时结束了,如果把 set_time_limit(0); 前的注释符//去除,则程序直到1才结束。

复制代码 代码如下:

//set_time_limit(0);
$i=1500;
include ("inc/conn.php");
while($i>0)
{
$sql="INSERT INTO php (php)
VALUES ('$i')";
if ($conn->execute($sql)===flase)
{
//echo "数据插入错误".$conn->errormsg();
}
else
{
$phpid=$conn->Insert_ID();
echo $i."已经存入数据库,编号:".$phpid;
}
$i--;
echo "
";
}
?>
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