您好,欢迎访问一九零五行业门户网

php Maximum execution time of 30 seconds exceeded 网页超时的解决方法

我们在做一个采集程序时会碰到页面执行过久导致提示php maximum execution time of 30 seconds exceeded错误了,出现这个问题解决办法非常的简单只要在页面顶部设置set_time_limit(0)即可.
先们来看例子,代码如下:
function geturl( $url,$userinfo,$header) { $ch = curl_init(); $timeout = 1; curl_setopt ($ch, curlopt_url, $url); curl_setopt ($ch, curlopt_httpheader, $header); curl_setopt ($ch, curlopt_referer, http://www.phprm.com/); curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt ($ch, curlopt_useragent, $userinfo); curl_setopt ($ch, curlopt_connecttimeout, $timeout); $contents = curl_exec($ch); curl_close($ch); return $contents ; //开源软件:phprm.com}
//执行一会发现 
fatal error: maximum execution time of 30 seconds exceeded in d:phpappservwww360dtest.php on line 3 
后面我在页面顶部加上如下代码:
set_time_limit(0);//设置超时时间
这样就没有问题了,下面我再简单介绍一下set_time_limit详解
set_time_limit — 限制最大的执行时间set_time_limit(ph3 , php4)set_time_limit — 限制最大的执行时间语法:void set_time_limit (int seconds)说明:设定一个程式所允许执行的秒数,如果到达限制的时间,程式将会传回错误.
它预设的限制时间是30秒,max_execution_time的值定义在结构档案中(在php3中叫做php3.ini,在php4、php5则叫做php.ini),如果将秒数设为0,表示无时间上的限制.
当呼叫此函式时,set_time_limit()会从零重新开始计算最长执行的时间,也就是说,如果最长执行时间为预设的30秒,而在呼叫此函式set_time_limit(20)之前已花了25秒来执行程式,则程式最长执行的时间将会是45秒.
有些朋友说可以修改apache配置,但我没测试大家自动设置吧.
1、 修改是apache设置,在php.ini中找到一个参数:max_execution_time
将后面的值调大,然后重新启动apache服务(centos:service httpd restart),就ok了.如:max_execution_time = 600
本文地址:
转载随意,但请附上文章地址:-)
其它类似信息

推荐信息