Mar 21, 2016
0
Level 1
My CURL instance is called twice
I'm using CURL for an API.
There is two endpoint deepSearchCreate and deepSearch.
deepSearchCreate create an instance and scan my content and return an id.
After around 20 seconds deepSearch return the result of the first created instance.
My problem is :
The script never end to load and the deepSearchCreate is call in loop. On the API dashboard I see lot of instance, while I have called the script only one time...
My script :
$url = 'http://api.com/api.asmx/deepSearchCreate';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'apikey=API_KEY&search='.strip_tags(trim($article->contenu)).'&source=&searchid=');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json, TRUE);
$id = $array['collection']['@attributes']['id'];
sleep(30)
$url = 'http://api.com/api.asmx/deepSearch';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'apikey=API_KEY&id='.$id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json, TRUE);
$status = $array['collection']['@attributes']['status'];
$nb_duplicate = $array['collection']['links']['@attributes']['count'];
if($nb_duplicate > 0){
foreach($array['collection']['links']['link'] as $result){
$site_duplicate .= $result['url'].'<br/>';
$check_duplicate = true;
}
}else {
$duplicate = 'no';
}
Update :
I think i have this problem, can someone help me ?
http://stackoverflow.com/questions/9158985/php-curl-script-run-twice-when-printing-return-string
Please or to participate in this conversation.