火车头采集器对接织梦cms图集发布时, 采集网上图片超时的解决方法
2017-10-04 23:07
519 查看
背景介绍:
火车头采集器对接织梦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; }
参考: 丝魅吧
相关文章推荐
- 织梦cms网上复制图片不可用的解决方法
- 织梦CMS采集时keywords字段无法添加过滤规则的解决方法
- 织梦CMS采集时keywords字段无法添加过滤规则的解决方法
- 织梦会员中心发布图集缩略图失败BUG解决方法
- JEECMS的新浪图集在IE9、10不能显示大图片BUG的解决方法
- 织梦DedeCMS列表页、内页调用图集多张图片的方法
- 简单解决织梦CMS提示“系统无此标签,可能已经移除”的方法
- 采集百度搜寻结果,图片不显示的解决方法
- AFNetworking Xcode6上传图片崩溃或超时解决方法
- 解决织梦CMS后台验证码不正确的四种方法
- 织梦火车头采集文章图集+采集附加字段(附带文章和图集的发布模块)
- Dedecms图集上传zip压缩包解压图片顺序不对问题的解决方法
- dede织梦上传图片出现提示302错误ERROR解决方法
- 织梦DEDECMS更换目录后页面内的图片和缩略图无法显示解决方法
- 织梦dedecms5.7后台发布文章提示“标题不能为空”解决方法
- 记录下 linux安装织梦cms遇到的问题和解决方法
- PHP CURL采集百度搜寻结果图片不显示问题的解决方法
- 织梦dedecms 采集的文章重复或内容文章标题重复批量删除的解决方法
- dedecms(织梦cms)5.6出现Upload filetype not allow错误的原因及解决方法
- dedecms织梦图集上传图片无水印的解决办法