Sorry for this question, but I already 3 days no idea where the error. I have one page on my own site, which show ip address of user like this :
<?php
echo "<br>"."Your IP address :"."<br>";
echo @$_SERVER['HTTP_CLIENT_IP']."<br>";
echo @$_SERVER['HTTP_X_FORWARDED_FOR']."<br>";
echo @$_SERVER['REMOTE_ADDR']."<br>"
?>
and when I send only one request via curl, this page show address of proxy, exactly as I want :
$ch = curl_init("http://mysite/youIp.php");
$proxy = '180.210.205.107:3128';
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_scraped_page = curl_exec($ch);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
Result :
But all fail when I try to use multi requests via curl function:
$proxy = '180.210.205.107:3128';
function multirequest($urls)
{
$multi = curl_multi_init();
$handles = [];
$htmls = [];
for($i=0; $i<count($urls);$i++)
{
$url = $urls[$i];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($multi, $ch);
$handles[$url] = $ch;
}
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK)
{
if (curl_multi_select($multi) == -1)
{
usleep(1);
}
do
{
$mrc = curl_multi_exec($multi, $active);
}while($mrc == CURLM_CALL_MULTI_PERFORM);
}
foreach($handles as $channel)
{
$html = curl_multi_getcontent($channel);
$htmls[] = $html;
curl_multi_remove_handle($multi, $channel);
}
curl_multi_close($multi);
return $htmls;
}
run requests to urls from array(actually, $urls
contains only 1 url - to my own page) :
var_dump($urls);
// only 1 url -> http://mysite/youIp.php
foreach($urls as $url)
{
$htmls = multirequest($url);
foreach($htmls as $html)
{
echo $html;
}
}
and as result I see my server ip address :
I have no idea why this code not work. If you see where I made a mistake please, help. Thank you!