2011-06-01 92 views
0

我寫了一段文件,當我在本地主機上嘗試時,它正確地爲我提取數據。它也適用於另一臺服務器。但是,當我將它傳送到服務器時,它顯示警告消息...PHP Curl Extension無法正常工作

Warning: (null)(): 4 is not a valid cURL handle resource in Unknown on line 0

任何人都可以提出什麼樣的變化我在.htacess做出和我需要在控制面板去做出改變......

這裏是我使用的代碼片。

function multiRequest($data, $options = array()) { 

    // array of curl handles 
    $curly = array(); 
    // data to be returned 
    $result = array(); 

    // multi handle 
    $mh = curl_multi_init(); 

    // loop through $data and create curl handles 
    // then add them to the multi-handle 
    foreach ($data as $id => $d) { 
$curly[$id] = curl_init(); 

$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d; 
curl_setopt($curly[$id], CURLOPT_URL,   $url); 
curl_setopt($curly[$id], CURLOPT_HEADER,   0); 
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1); 

// post? 
if (is_array($d)) { 
    if (!empty($d['post'])) { 
    curl_setopt($curly[$id], CURLOPT_POST,  1); 
    curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']); 
    } 
} 

// extra options? 
if (!empty($options)) { 
    curl_setopt_array($curly[$id], $options); 
} 

curl_multi_add_handle($mh, $curly[$id]); 
    } 

    // execute the handles 
    $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); 
    curl_multi_remove_handle($mh, $c); 
    } 

    // all done 
    curl_multi_close($mh); 

    return $result; 
} 

for ($i=0;$i<$length;$i++){ 
$no = $start + $i; 
$data[$i]['url'] = 'http://abc.php'; 
$data[$i]['post'] = array(); 
$data[$i]['post']['regno'] = $no; 
} 

$r = multiRequest($data); 

// the I have a code to use the $r (result array obtained) 

感謝

+0

需要一些代碼兄弟我們可以建議一些東西 – 2011-06-01 14:45:56

+1

改變.htaccess/cpanel不會幫助這個錯誤。這是你的代碼中的一個錯誤。可能你會覆蓋你的curl句柄變量,使它不再是一個捲曲句柄。請發佈相關代碼。因爲這個問題不能得到適當的回答。 – 2011-06-01 14:46:48

+0

這是我使用的代碼 – 2011-06-01 14:46:55

回答

1

這並不意味着捲曲擴展不工作,恰恰相反。 CURL正在工作,但是當您嘗試訪問您傳遞給捲曲的選項時,您未通過捲曲資源處理程序。

例如,

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

您需要使用$ CH的處理程序,這是我想像你是不是在做什麼?

作爲一個側面說明,如果curl沒有安裝,你會得到一個異常。除非你在包裝它try/catch函數存在。

+0

實際上我正在嘗試在頁面中請求大約1000個請求 – 2011-06-01 14:53:16