I have just 2 references and need to parse their. One reference is in .txt file, second was added in code :
$file = file('links.txt');
$urls = [];
array_push($urls, 'https://www.facebook.com');
array_push($urls, $file[0]);
The .txt File conteins only one row - https://www.facebook.com.
var_dump($urls);
echo "<br>";
array(2) { [0]=> string(24) "https://www.facebook.com" 1=> string(24) "https://www.facebook.com" }
Now I need to get content from these pages via curl. My Code :
$multi = curl_multi_init();
$handles = [];
foreach($urls as $url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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);
$strlen = strlen($html);
echo "Content length :".$strlen."<br>";
curl_multi_remove_handle($multi, $channel);
}
Finally, this code must output 2 same digits, but I have this :
<br>
Content Len :0
<br>
<br>
In browser :
Could someone to say - where is error ?

Aucun commentaire:
Enregistrer un commentaire