Created
May 3, 2011 21:33
-
-
Save athoune/954308 to your computer and use it in GitHub Desktop.
mapreduce with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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