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

更新时间:2019-05-11    来源:php常用代码    手机版     字体:

【www.bbyears.com--php常用代码】

先们来看例子

例子

 代码如下

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.111cn.net/");
 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 ;
 
}

执行一会发现

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%C5%E4%D6%C3/" target="_blank">apache配置,但我没测试大家自动设置吧。

1、 修改是APACHE设置,在PHP.INI中找到一个参数:

max_execution_time

将后面的值调大,然后重新启动APACHE服务(centos: service httpd restart),就OK了。

max_execution_time = 600

本文来源:http://www.bbyears.com/jiaocheng/50511.html

猜你感兴趣

热门标签

更多>>

本类排行