Created
July 19, 2013 05:59
-
-
Save jekamozg/6036970 to your computer and use it in GitHub Desktop.
Curl example
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
/** | |
* 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