Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php Maximum execution time of 30 seconds exceeded 网页超时的解决方法

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

发布时间:2018-10-10   编辑:www.jquerycn.cn
jquery中文网为您提供php Maximum execution time of 30 seconds exceeded 网页超时的解决方法等资源,欢迎您收藏本站,我们将为您提供最新的php Maximum execution time of 30 seconds exceeded 网页超时的解决方法资源
我们在做一个采集程序时会碰到页面执行过久导致提示php Maximum execution time of 30 seconds exceeded错误了,出现这个问题解决办法非常的简单只要在页面顶部设置set_time_limit(0)即可。

先们来看例子

例子

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2843')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2843>

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

后面我在页面顶部加上

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5582')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5582>

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

您可能感兴趣的文章:
Maximum execution time of 30 seconds exceeded in
Fatal error: Maximum execution time of 30 错误解决办法
php程序执行超时解决办法(Fatal error: Maximum execution time of 30)
PHP程序时出现 Fatal error: Maximum execution time of 30 seconds exceeded in 提示
php Maximum execution time of 30 seconds exceeded 网页超时的解决方法
php设置运行时间的方法
php页面函数设置超时限制
php set_time_limit()用法测试详解
调整PHP上传文件大小限制
PHPExcel导出Excel文件时出现错误的解决办法

[关闭]