To get some API data, I am using following cURL code in PHP:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "some_api_url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
if(curl_errno($ch))
{
echo "cURL error: " . curl_error($ch);
}
curl_close($ch);
echo $response;
Now, the question is that what is the point of having CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
in my code?
The code does pretty well even without these two settings.
Then why do docs and people on Internet advise using this particular settings?
UPDATE
I am not asking the difference between these two curl setting options. Rather than I asked about the need to include them in my code. The suggested post link (due to this, my question is almost marked as duplicate) does not address to my question. Also people there have so much different opinions and misjudge each other in various comments.