how to know which response data is associated with its requested url (using RollingCurl.php) ?
Posted
by Ken
on Stack Overflow
See other posts from Stack Overflow
or by Ken
Published on 2010-03-25T11:25:49Z
Indexed on
2010/03/25
11:33 UTC
Read the original article
Hit count: 370
I am writing a web application that grabs the http response headers from multiple sites (with RollingCurl.php) 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 has an url ($info[‘url’]) where the requested url was redirect.to, and it’s quite expected. But how to put a requested url in $info ($info[‘requested_url’]) and 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();
if ( $urls ) {
$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);
}
function request_callback($response, $info) {
global $json;
$json['status'][] = $info;
}
from RollingCurl.php:
// send the return values to the callback function.
$callback = $this->callback;
if (is_callable($callback)){
$info[‘requested_url’] = ??? // How to put requested url here???
call_user_func($callback, $output, $info);
}
© Stack Overflow or respective owner