| Krist_ALL |
22.11.2009 17:13 |
Вопрос по мульткурлу
Юзаю мультикурл и мне нада получить html код страницы, чтобы отпарсить его но в ответ какието 0 и -1
PHP код:
//создаем обработчик для параллельной работы с URL'ами
$mh = curl_multi_init();
//создаем обработчики для каждого отдельного URL и добавляем их в $mh
$handles = array();
for ($i = 0; $i < count($adresa); $i++) {
$handles[$i] = curl_init();
curl_setopt($handles[$i], CURLOPT_URL, $adresa[$i]);
curl_setopt($handles[$i], CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($handles[$i], CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($handles[$i], CURLOPT_TIMEOUT, 6);
curl_setopt($handles[$i], CURLOPT_HEADER, 1);
curl_setopt($handles[$i], CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
curl_setopt($handles[$i], CURLOPT_REFERER, 'http://google.com');
curl_setopt($handles[$i], CURLOPT_POST, 1);
curl_setopt($handles[$i], CURLOPT_POSTFIELDS, "...........................");
curl_multi_add_handle($mh, $handles[$i]);
}
$running = null;
do {
$result = curl_multi_exec($mh, $running);
echo htmlspecialchars($result);
} while ($running > 0);
//закрываем обработчики
for ($i = 0; $i < count($handles); $i++) {
curl_multi_remove_handle($mh, $handles[$i]);
}
|