2

我有一个 Alexa 前 100 万的列表。我想检查这 100 万个站点中哪些是具有页面 www.domain.com/pageNameUrl 的站点。我试过了

foreach($sites as $site){    
  $file_headers = @get_headers($site);
  if(strpos($file_headers[0],"200 OK") !== false) {
    $exists = true;
    //save site name code...
  } else {
    $exists = false;
  }
}

但是这段代码需要太多时间。浏览所有站点需要 1 个月甚至更长时间。还有其他更快的方法吗?

4

1 回答 1

0

我认为 php 不是该工作的合适人选。您可能会考虑像 nodeJs 这样非常适合异步作业的东西。看看这个(示例取自https://npmjs.org/package/crawler

var Crawler = require("crawler").Crawler;

var c = new Crawler({
    // here you can define, how many pages you want to do in parallel
    "maxConnections":10,

    // This will be called for each crawled page
    "callback":function(error,result,$) {
        // mark this page as available or not based on the reponse
        console.log(result.statusCode);
    }
});

// Queue all your urls in a loop, they all will be push asynchronously to the crawler job
c.queue("http://www.google.de");
c.queue("http://www.amazon.de");
c.queue("http://www.facebook.de");
于 2013-05-25T10:25:15.950 回答