我有一份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;
}
}但是这段代码花费了太多的时间。这将需要一个月甚至更长的时间来浏览所有的网站。有没有其他更快的方法?
发布于 2013-05-25 18:25:16
我认为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");https://stackoverflow.com/questions/16748494
复制相似问题