是否有任何apache配置可以增强web爬网性能


Are there any apache configurations to enhance web crawling performance?

我有一个php网络爬虫,当它在localhost上运行时,通常会在几页后冻结,让我的网络浏览器显示加载标志,而不是其他。

我已经检查了我的代码,可能有错误。。尽管在看了最后几个小时之后,我准备探索其他的可能性。

当我的scraper运行时,它会在不同进程开始和结束时转储信息。我也经常慌乱();以确保浏览器显示最新消息。(这为浏览器提供了控制台类型的外观)。

我现在研究Apache配置的原因是,我的程序并不总是冻结在同一个地方。有时,当它搜索要添加到队列中的新URL的"a"标签时,它会冻结;有时,它会在下载xhtml数据时冻结,此时:

 private function _getXhtml() {
        $curl = curl_init();
        if (!$curl) {
            throw new Exception('Unable to init curl. ' . curl_error($curl));
        }
        curl_setopt($curl, CURLOPT_URL, $this->_urlCurrent);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        // Faking user agent
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        $xhtml = curl_exec($curl);
        if (!$xhtml) {
            $xhtml = null;
            echo 'PROBLEM' . $this->_urlCurrent . '<br />';
            //throw new Exception('Unable to read XHTML. ' . curl_error($curl));
        }
        curl_close($curl);
        return $xhtml;
    }

除此之外,我想知道我是否可以对apache的配置文件或PHP.ini进行任何修改,以增强用于web抓取的localhost环境?

如有任何帮助,我们将不胜感激。

更新:

我相信我已经把它缩小到了Zend_Dom_Query。这就是为什么我的应用程序在不同阶段崩溃的原因(有时是在抓取爬行列表的href时,有时是在页面中寻找要"收获"的特定内容时)

下面是我的输出示例。

此处,应用程序在第一页上崩溃。。获取url时

    string(25) "Scraping page number 0..." 
string(9) "Mining..." 
string(15) "Getting <a>...." 
string(24) "Finished getting <a>...." 
string(20) "Getting <a href>...." 
string(43) "Mining page http://www.a-site.co.uk/ ..." 
string(17) "New page found..." 
string(18) "Page confirmed...." 
string(29) "Finished Getting <a href>...." 
string(20) "Getting <a href>...." 
string(43) "Mining page http://www.a-site.co.uk/ ..." 
string(29) "Finished Getting <a href>...." 
string(20) "Getting <a href>...."

这里,应用程序在提取元素时失败

string(25) "Scraping page number 5..."
string(9) "Mining..."
//This bit loops for around 70 URLS
string(15) "Getting <a>...."
string(24) "Finished getting <a>...."
string(20) "Getting <a href>...."
string(48) "Mining page http://www.a-site.org ..."
string(29) "Finished Getting <a href>...."
//end loop
string(70) "Harvesting http://www.a.site.org/a-url-path/..."
string(19) "Harvesting html element..."

脚本看起来不错,所以可能是您正在爬网的站点尝试添加

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,5); //timeout in seconds.
curl_setopt($curl, CURLOPT_TIMEOUT, 30); //timeout in seconds.

你也可以试着让你的刮刀看起来更像一个真正的浏览器。就我个人而言,我使用我自己的标题,我可以用fiddler2找到,然后用卷曲的方式重新创建它们。