连续用file或者fsockopen等读取1000多个远程页面,然后用explode拆分字符串,把结果保存到文本文件中。但是每次运行到大概一小半页面后就运行不下去了。注明,我已经把时间limit设置为0
用ob_end_clean和flush显示进度
先怀疑是不是存放页面地址的数组过大,后来换成存到数据库中一个一个读取也是一样的。
后来怕是explode出来的字符串数组占用内存什么的,每次用unset,但是也没有变化
后来把explode语句注释掉,就可以顺利完成,难道是explode的原因?请各位大大指教,困扰了好久了

解决方案 »

  1.   

    内存不够了把
    用ini_set("memery_limit", -1)拭下
    不过这么多网页,建议还是用c++或是java编个多线程的爬虫处理把
      

  2.   

    set_time_limit(0);mysql_connect("localhost", "", "") or die ("Problem connecting to DataBase");
    $query = "select code from test";
    $result = mysql_db_query("aa", $query);
    while ($r = mysql_fetch_array($result)) {unset($str);
    unset($str_ary);
    unset($str_item);
    $url = "http://example.com/".$r[0].".html"; 
    $str = implode("",file($url)); 
    $str_ary = explode("上期同比",$str); $str_item = explode("<tr",$str_ary[1]);
    for ($k=1;$k<count($str_item)-9;$k++)
    {
    $tmp=ereg_replace("[\r\n\t]","",strip_tags('<tr'.$str_item[$k]));
    if (eregi('年度', $tmp)) echo $r[0]." ".$tmp."<br>";
    }ob_flush();
    flush();
    }