PHP script execution time limit, the default is 30m Solution: set_time_limit(); or modify PHP.ini to set max_execution_time time (not recommended)
There are several problems that need to be solved when using php to refresh the browser
If the client browser is closed, the program may be forced to terminate. The solution: ignore_user_abort will still execute normally even if the page is closed
If the program keeps executing, it is likely to consume a lot of resources. The solution is to use sleep to sleep the program for a while, and then execute it
Code for PHP scheduled execution:
The code is as follows
代码如下 |
复制代码 |
ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(3000);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=5;// 每隔5s运行
//方法1--死循环
do{
echo '测试'.time().' ';
sleep($interval);// 等待5s
}while(true);
//方法2---sleep 定时执行
require_once './curlClass.php';//引入文件
$curl = new httpCurl();//实例化
$stime = $curl->getmicrotime();
for($i=0;$i<=10;$i++){
echo '测试'.time().' ';
sleep($interval);// 等待5s
}
ob_flush();
flush();
$etime = $curl->getmicrotime();
echo ' ';
echo round(($etime-stime),4);//程序执行时间
|
|
Copy code |
|
ignore_user_abort();//Close the browser and the PHP script can continue to execute.
set_time_limit(3000); // Through set_time_limit(0), the program can be executed without limit
$interval=5;//Run every 5s
//Method 1--Infinite Loop
do{
echo 'Test'.time().'
';
sleep($interval);//wait 5s
}while(true);
//Method 2---sleep scheduled execution
require_once './curlClass.php';//Introduction file
$curl = new httpCurl();//Instantiation
$stime = $curl->getmicrotime();
for($i=0;$i<=10;$i++){
echo 'Test'.time().'
';
}
ob_flush();
flush();
$etime = $curl->getmicrotime();
echo '
';
echo round(($etime-stime),4);//Program execution time
http://www.bkjia.com/PHPjc/631659.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631659.htmlTechArticlePHP script execution time limit, the default is 30m Solution: set_time_limit(); or modify PHP.ini to set max_execution_time Time (not recommended) Using php to refresh the browser needs to be solved...