This seems to work as expected for me - allowing me to get the content from a curl_multi operation into variables :
(Thanks go to many other notes in related documentation (there is much copy/pasting) all I did was add the relevant line(s))
<?
$aURLs = array("http://www.php.net","http://www.w3cschools.com"); // array of URLs
$mh = curl_multi_init(); // init the curl Multi
$aCurlHandles = array(); // create an array for the individual curl handles
foreach ($aURLs as $id=>$url) { //add the handles for each url
$ch = curl_setup($url,$socks5_proxy,$usernamepass);
$ch = curl_init(); // init curl, and then setup your options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // returns the result - very important
curl_setopt($ch, CURLOPT_HEADER, 0); // no headers in the output
$aCurlHandles[$url] = $ch;
curl_multi_add_handle($mh,$ch);
}
$active = null;
//execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
}
while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
/* This is the relevant bit */
// iterate through the handles and get your content
foreach ($aCurlHandles as $url=>$ch) {
$html = curl_multi_getcontent($ch); // get the content
// do what you want with the HTML
curl_multi_remove_handle($mh, $ch); // remove the handle (assuming you are done with it);
}
/* End of the relevant bit */
curl_multi_close($mh); // close the curl multi handler
?>
PHP.mk документација
curl_multi_getcontent
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
function.curl-multi-getcontent.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
function.curl-multi-getcontent.php
curl_multi_getcontent
Референца за `function.curl-multi-getcontent.php` со подобрена типографија и навигација.
curl_multi_getcontent
класата mysqli_driver
curl_multi_getcontent — Врати ја содржината на cURL рачката ако CURLOPT_RETURNTRANSFER (двоен наводник)
= NULL
Враќа CURLOPT_RETURNTRANSFER е опција што е поставена за специфична рачка, тогаш оваа функција ќе ја врати содржината на таа cURL рачка во форма на стринг.
Вратени вредности
Врати ја содржината на cURL рачката ако CURLOPT_RETURNTRANSFER е поставено или null ако не е поставено.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 |
handle беше вратено при неуспех. CurlHandle
инстанца сега; претходно, а resource се очекуваше.
|
Белешки од корисници 2 забелешки
michael at xendica dot com ¶
пред 11 години
Relakuyae ¶
12 години пред
You can use curl_multi_getcontent() on a curl handle that was executed with curl_exec() (and not added to a multi handle).
However, this is not very useful because curl_multi_getcontent() will return the same as curl_exec() then.
<?php
$ch = curl_init('http://www.example.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$a = curl_exec($ch);
$b = curl_multi_getcontent($ch);
var_dump($a === $b);
curl_close($ch);
?>
will return:
bool(true)