我写了一段文件,当我在本地主机上尝试时,它正确地为我提取数据。它也适用于另一台服务器。但是,当我将它传送到服务器时,它显示警告消息...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)
感谢
需要一些代码兄弟我们可以建议一些东西 – 2011-06-01 14:45:56
改变.htaccess/cpanel不会帮助这个错误。这是你的代码中的一个错误。可能你会覆盖你的curl句柄变量,使它不再是一个卷曲句柄。请发布相关代码。因为这个问题不能得到适当的回答。 – 2011-06-01 14:46:48
这是我使用的代码 – 2011-06-01 14:46:55