Home  >  Article  >  Backend Development  >  How to set program running time in php

How to set program running time in php

青灯夜游
青灯夜游Original
2021-05-08 17:54:564753browse

Setting method: 1. In the "php.ini" file, modify the value of the "max_execution_time" item; 2. Use the "ini_set('max_execution_time', value)" statement to set; 3. Use "set_time_limit( Value)" statement setting.

How to set program running time in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Method 1: In php.ini Increase the running time in

max_execution_time=300

Method 2: Use the ini_set() function

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

Method 3: Use the set_time_limit() function

set_time_limit(0);

The number in the brackets is the execution time. If it is zero, it means that it will be executed permanently until the end of the program. If it is a number greater than zero, the program will end after the set number of seconds, regardless of whether the program execution is completed.

A simple example is to display 1500 statements on a web page. If the expiration time is not set, the program execution will end at 791. If the comment character // before set_time_limit(0); is removed, then The program does not end until 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 "<hr>"; 
} 
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set program running time in php. For more information, please follow other related articles on the PHP Chinese website!

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