What I have in place, is a domain availability check, which connects up to an API and outputs \"Available: and Unavailable:\" from $tmp. Ths below code will only check the avail
This should answer your question: Persistent/keepalive HTTP with the PHP Curl library?
comment followup:
function getCurlPage($pageSpec) {
if (is_null($ch))
static $ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
} else {
curl_setopt($ch, CURLOPT_URL, $pageSpec);
}
$tmp = curl_exec($ch);
... do NOT close the curl handle, otherwise do the rest the same as before ...
}
Probably won't work as is, doing this off the top of my head and with only 2 hours sleep, but this should be enough to get you started.
And by the way, there's no need to do doublequotes for GetCurlPage("$url")
, it's a waste of parser time, as PHP will have to create a new empty string, stuff $url
into it, and pass the new string on down. Just do GetCurlPage($url)
.