Home php教程 php手册 php页面函数设置超时限制

php页面函数设置超时限制

Jun 02, 2016 am 09:13 AM

碰到页面程序执行超时时会提醒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();
Copy after login

对于文件或程序代码可使用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表示不限时.


本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24