Skip to content

Instantly share code, notes, and snippets.

@jekamozg
Created July 19, 2013 05:59
Show Gist options
  • Save jekamozg/6036970 to your computer and use it in GitHub Desktop.
Save jekamozg/6036970 to your computer and use it in GitHub Desktop.
Curl example
/**
* Curl request
* @param type $url
* @return type
*/
public function getCurlResponse($url) {
$ch_req = curl_init();
curl_setopt($ch_req, CURLOPT_URL, $url);
curl_setopt($ch_req, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch_req, CURLOPT_VERBOSE, 0);
curl_setopt($ch_req, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_req, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch_req, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch_req, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)');
$curl_result = curl_exec($ch_req);
$info = curl_getinfo($ch_req);
curl_close($ch_req);
return array(
'result' => $curl_result,
'info' => $info,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment