A.kapoor A.kapoor - 7 months ago 6
PHP Question

curl take long time and curlinfo_http_code returns 0

I'm using

curl
but it take long time (about 90 second) and eventually when i check
curlinfo_http_code
it return 0 .

That's not matter for me why and how this problem occur because its just for sometimes .

I wanna if
CURLOPT_URL
have any problem and my respons take long time just i want
disable
curl instantly .


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,"id=$id&amount=$amount&callback=$callback&resnum=$resnum");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$res = curl_exec($ch);
curl_close($ch);
return $res;

Answer

You can modify your curl call something like:

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,"id=$id&amount=$amount&callback=$callback&resnum=$resnum");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30); 
$res = curl_exec($ch);
curl_close($ch);
return $res;

for more options, have a look at curl_setopt documentation on php.net

Comments