I am having an array of urls which i m accessing with curl api to get the data in exml format ,but some urls out of them are throwing an error that string could not be parsed as xml but when i access that url separately in different file it gives me proper result.But in first file where i m iterating the urls array there is throwing exception on some urls.Code for first file is below.
<?php
function httpGet($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'header-Id:value1',
'header-Token:value2'
));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
function loopData($url){
try {
echo 'looped ';
$data2 = httpGet($url);
$xml2 = new SimpleXMLElement($data2);
loopData($xml2->nextUrl);
}
catch(Exception $e){
var_dump($e);
}
}
foreach($url as $array){
echo 'new url ';
//echo $array;
loopData($array);
}
?>
If my url array is having 20 urls some urls while iterating throws an exception but when they are accessed separately,the urls gives proper result.
Aucun commentaire:
Enregistrer un commentaire