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

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
