这篇文章主要介绍了php页面函数设置超时限制的方法,可通过函数控制超时限制,也可通过修改php配置文件实现修改超时限制,需要的朋友可以参考下
本文实例讲述了php页面函数设置超时限制的方法。分享给大家供大家参考。具体方法如下:
碰到页面程序执行超时时会提醒Fatal error: Maximum execution time of 300 seconds exceeded 是因为程序执行时间超过了最大允许执行时间,解决办法我们总结了几个供大家选择.
对于函数我们可以常用下面方法,直接给函数设置超时时间来操作,代码如下:
复制代码 代码如下:
declare(ticks = 1);
function a(){
sleep(10);
echo "a finishi ";
}
function b(){
echo "Stop ";
}
function c(){
usleep(100000);
}
function sig(){
throw new Exception;
}
try{
pcntl_alarm(1);
pcntl_signal(SIGALRM, "sig");
a();
pcntl_alarm(0);
}catch(Exception $e){
echo "timeout ";
}
b();
a();
b();
对于文件或程序代码可使用set_time_limit只是设置你的PHP程序的超时时间.
解决方法:
1.修改php.ini文件,代码如下:
复制代码 代码如下:
max_execution_time = 30; // Maximum execution time of each script, in seconds 原值30秒,你可以改大点.
改完后记得重启php,该方法改了后对所有程序生效.
2.修改你的程序,在你需要耗时超过默认值(30秒)的脚本中,加入代码:
复制代码 代码如下:
set_time_limit(300); // 最大执行时间这里设置300秒
设置成0表示不限时。
希望本文所述对大家的PHP程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version