Skip to content

Instantly share code, notes, and snippets.

@jagroop
Created August 25, 2017 14:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagroop/22a548015e28ca1e1408fd6b6c1e6f68 to your computer and use it in GitHub Desktop.
Save jagroop/22a548015e28ca1e1408fd6b6c1e6f68 to your computer and use it in GitHub Desktop.
PHP Multi curl to check if domains are indexed in google
<?php
function multiRequest($data, $options = array()) {
$curly = array();
$result = array();
$mh = curl_multi_init();
foreach ($data as $id => $d) {
$url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($d);
$curly[$id] = curl_init($url);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, false);
curl_setopt($curly[$id], CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curly[$id], CURLOPT_HTTPGET, 1);
curl_setopt($curly[$id], CURLOPT_NOBODY, true);
curl_setopt($curly[$id], CURLOPT_USERAGENT, 'Chrome 10');
curl_multi_add_handle($mh, $curly[$id]);
}
$running = null;
do {
curl_multi_exec($mh, $running);
} while($running > 0);
// get content and remove handles
foreach($curly as $id => $c) {
// $result[$id] = curl_multi_getcontent($c);
$result[$id] = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_multi_remove_handle($mh, $c);
}
curl_multi_close($mh);
return $result;
}
$data = [
"stackoverflow.com",
"laracasts.com",
"quora.com",
"example.com",
"kjahdskljahsd.com",
"scotch.io"
];
$r = multiRequest($data);
echo '<pre>';
var_dump($r);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment