Skip to content

Instantly share code, notes, and snippets.

@athoune
Created May 3, 2011 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/954308 to your computer and use it in GitHub Desktop.
Save athoune/954308 to your computer and use it in GitHub Desktop.
mapreduce with PHP
require 'lib/worker.php';
function getTitle($url) {
$html = file_get_contents("http://$url");
if($html == FALSE) {
throw new Exception("can't fetch url");
}
preg_match('/<title>(.*)<\/title>/i', $html, $matches);
return html_entity_decode($matches[1]);
}
if($argv[1] == '--mapreduce') {
$sites = array(
'linuxfr.org',
'www.slashdot.org',
'www.boingboing.net',
'www.rue89.com',
'blog.makezine.com',
'www.4chan.org',
'news.ycombinator.com',
'danstonchat.com',
'freshmeat.net',
'www.flickr.com'
);
$worker = new Worker();
foreach($worker->batch('getTitle', $sites) as $title) {
echo " $title\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment