I decided to take a stab at using CURL in the hopes it would make things more efficient. Namely, I wanted the application to stop trying to retrieve a site after a specified period of time and go on to the next site. Since I couldn't find a way to do that with file_get_contents, I start to write CURL in it's place.
What's happening now is that browser is timing out when I use the curl code and I can't find a way to keep it from happening. Here is the code I'm currently employing.
Code: Select all
<?php
$curlResource = curl_init();
// set CURL options
curl_setopt($curlResource, CURLOPT_URL, 'http://'.$protocolessURL); // set destination.
curl_setopt($curlResource, CURLOPT_FOLLOWLOCATION, true); // allow CURL to follow redirect headers.
curl_setopt($curlResource, CURLOPT_MAXREDIRS, 2); // allow only on redirect before failure.
// curl_setopt($curlResource, CURLOPT_MUTE, true); // run without errors being displayed.
curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true); // return output as string rather than to screen.
curl_setopt($curlResource, CURLOPT_CONNECTTIMEOUT, $connectionTimeOut); // set time limit on connection
curl_setopt($curlResource, CURLOPT_LOW_SPEED_TIME, $attemptTimeOut); // set time to fail per fetch attempt
curl_setopt($curlResource, CURLOPT_TIMEOUT, $maxTimeOut); // maximum time a curl function can run
curl_setopt($curlResource, CURLOPT_USERAGENT, $userAgent); // the user agent to be sent in http requests
curl_setopt($curlResource, CURLOPT_NOSIGNAL, true);
// execute CURL operation
$contents = curl_exec($curlResource);
print curl_error($curlResource);
// close CURL session
curl_close($curlResource);
?>