• 火车头采集器对接织梦cms图集发布时, 采集网上图片超时的解决方法


    背景介绍:

    火车头采集器对接织梦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}
    ";
    			}
    		}
        }
        return $rsimg;
    }
    

  • 相关阅读:
    Python3 B格注释
    python 安装模块时提示报错:Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)
    sed的使用(数据的截取与插入)
    常见软件的安装
    淘宝镜像
    搭建 Node.js 开发环境
    解决 /lib64/libc.so.6: version `GLIBC_2.14' not found 的问题
    linux下 执行命令时提示cannot execute binary file
    web页面 显示 Resource interpreted as Stylesheet but transferred with MIME type text/plain的错误警告
    python+QT designer 做图形化界面EXE程序
  • 原文地址:https://www.cnblogs.com/haihua85/p/8681682.html
Copyright © 2020-2023  润新知