2010-03-25 15 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文檔以獲取該數組中的東西列表。

相關問題