I created a wrapper function for cURL in PHP. Its simplified version looks like this:
function curl_get_contents($url, $try = 1) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '1');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '1');
// Execute the curl session
$output = curl_exec($ch);
if ($output === FALSE) {
if ($try == 1) { //Try again
return $this->curl_get_contents($url, 2);
} else {
return false;
}
}
}
As you can see, I force a retry of the function if it fails. Do I need to run curl_close()
? Does PHP close all handles at the end of the script?
UPDATE
The linked question is extremely vague in its answer and doesn't support itself with data. I would really appreciate an answer based on perhaps a profiler that shows that PHP closes the connection immediately.