2010-03-25 34 views
1

我正在写一个Web应用程序,它抓取来自多个站点(与RollingCurl)的http响应头(,并行),然后将其存储在数组中,并在最后以JSON格式输出它。因为有些网站会重定向到新的位置,所以request_callback函数中的$ info(array)总是包含一个URL($ info ['url']),请求的url被重定向到了,这是相当期待的。 但如何将请求的网址推入数组(@ $ info ['requested_url'])以知道哪个$ info(响应数据)与其请求的url相关联?从RollingCurl.php如何知道哪些响应数据与其请求的url相关联(在RollingCurl.php中)?

$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; 
} 

//片段:

// 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); 
} 

回答

0

在回调函数中,$信息阵列应该有一个 'URL' 关键是这curl_multi用来做请求的URL。

请参阅关于curl_getinfo的php文档以获取该数组中的东西列表。

相关问题