Created
July 31, 2017 03:18
-
-
Save angelinetran/0e554340797846e9aaacea1f26978de1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Read file using cURL | |
* | |
* @param $url | |
* @param $header_params array | |
* @return $data | |
* | |
*/ | |
function fetch($url, $header_params = "") { | |
$url = preg_replace('/\s+/', '+', $url); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
if($header_params !== "") { | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_params); | |
} | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
// Set the maximum curl connect timeout to 6 seconds and then the complete request to 10 seconds; this bypasses the $connect_timeout and $timeout variables | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 6000); | |
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000); | |
$data = curl_exec($ch); | |
if(curl_exec($ch) === false) { | |
if ( $this->debug ) { $this->return_data .= "<p>curl: " . curl_error($ch) . "</p>\n"; } | |
return FALSE; | |
} | |
curl_close($ch); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment