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 に答える