背景介绍:
火车头采集器对接织梦cms图片集发布时, 对于多张(超过30张)大图片时, 经常会出现图集发布超时的情况.问题分析:
因为php对于资源的处理有默认的超时时间30秒, 而我尝试了好多方法, 都无法规避php运行30秒超时的这个问题. 所以想了个折中方案.折中方案:
在采集网上图片时, 判断当前采集了如果已经到了28秒, 那么就不再采集下面的其他图片.修改php代码:
打开文件dede/inc/inc_archives_functions.php 关注下列代码中begin_time和now_time判断部分.function GetCurContentAlbum($body, $rfurl, &$firstdd){global $dsql,$cfg_multi_site,$cfg_basehost,$cfg_ddimg_width;global $cfg_basedir,$pagestyle,$cuserLogin,$cfg_addon_savetype;$begin_time = time();require_once(DEDEINC.'/dedecollection.func.php');if(empty($cfg_ddimg_width)) $cfg_ddimg_width = 320;$rsimg = '';$cfg_uploaddir = $GLOBALS['cfg_image_dir'];$cfg_basedir = $GLOBALS['cfg_basedir'];$basehost = 'http://'.$_SERVER['HTTP_HOST'];//$img_array = array();//echo "<br />body: ".$body;preg_match_all("/(src)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);$img_array = array_unique($img_array);//echo "<br />";//print_r($img_array);$imgUrl = $cfg_uploaddir.'/'.MyDate($cfg_addon_savetype, time());$imgPath = $cfg_basedir.$imgUrl;if(!is_dir($imgPath.'/')){MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);CloseFtp();}$milliSecond = 'co'.dd2char( MyDate('ymdHis',time())) ;foreach($img_array as $key=>$value){for ($i = 0; $i < count($value); $i++) {$now_time = time();if ($now_time - $begin_time >= 28) {//已经执行了28秒, 很快就超时了, 不再获取其他外部资源, 避免超时return $rsimg;}$value1 = $value[$i];$value1 = trim($value1);$value1 = str_replace("src='", "", $value1);$value1 = str_replace("src=", "", $value1);$value1 = str_replace("src=\"", "", $value1);echo "<br />download img from web: ".$value1;if(preg_match("#".$basehost."#i", $value1) || !preg_match("#^http:\/\/#i", $value1) || ($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value1))){//echo "<br />continue;";continue;}$itype = substr($value1, -4, 4);if( !preg_match("#\.(gif|jpg|png)#", $itype) ) $itype = ".jpg";$rndFileName = $imgPath.'/'.$milliSecond.'-'.$key.'-'.$i.$itype;$iurl = $imgUrl.'/'.$milliSecond.'-'.$key.'-'.$i.$itype;//echo "<br /> iurl:".$iurl;//下载并保存文件$rs = DownImageKeep($value1, $rfurl, $rndFileName, '', 0, 30);if($rs){$info = '';$imginfos = GetImageSize($rndFileName, $info);$fsize = filesize($rndFileName);$filename = $milliSecond.'-'.$key.$itype;//保存图片附件信息$inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)VALUES ('0','$filename','$iurl','1','{$imginfos[0]}','$imginfos[1]','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";$dsql->ExecuteNoneQuery($inquery);$fid = $dsql->GetLastID();AddMyAddon($fid, $iurl);if($pagestyle > 2){$litpicname = GetImageMapDD($iurl, $cfg_ddimg_width);}else{$litpicname = $iurl;}if(empty($firstdd) && !empty($litpicname)){$firstdd = $litpicname;if(!file_exists($cfg_basedir.$firstdd)){$firstdd = $iurl;}}@WaterImg($rndFileName, 'down');$rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";}}}return $rsimg;}
参考: 丝魅吧