I am writing a web application that grabs (in parallel) the http response headers from multiple sites (with RollingCurl) then stores it in an array and at the end outputs it in JSON format.
Since some sites do redirects to new locations, $info (array) in “request_callback” function always contains an url ($info[‘url’]) where the requested url was redirected to, and it’s quite expected. But how to push a requested url into array (@ $info[‘requested_url’]) to know which $info (response data) is associated with its requested url?
$urls = array(
"http://google.com",
"http://microsoft.com"
// more urls here
);
$json = array();
$rc = new RollingCurl("request_callback");
$rc->window_size = 20;
foreach ($urls as $url) {
$request = new Request($url);
$rc->add($request);
}
$rc->execute();
echo json_encode($json);
exit;
function request_callback($response, $info) {
global $json;
$json['status'][] = $info;
}
// fragment from RollingCurl.php:
// send the return values to the callback function.
$callback = $this->callback;
if (is_callable($callback)){
$info[‘requested_url’] = **???** // How to get a requested url & push it into $info?
call_user_func($callback, $output, $info);
}