Skip to content

Instantly share code, notes, and snippets.

@jagroop jagroop/script.php
Created Aug 25, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.