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

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

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

set_time_limit(0);

括号里边的数字是执行时间,如果为零说明永久执行直到程序结束,如果为大于零的数字,则不管程序是否执行完成,到了设定的秒数,程序结束。
一个简单的例子,在网页里显示1500条语句,如果未设置失效时间,则程序执行到791时结束了,如果把 set_time_limit(0); 前的注释符//去除,则程序直到1才结束。 

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

} 
?>

相关文章:

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

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

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