Last active
August 29, 2015 14:16
-
-
Save k1ic/9cdf01f7e228b8387bf7 to your computer and use it in GitHub Desktop.
a simple demo of curl
This file contains 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
function simple_curl($url = '') { | |
if (!empty($url)) { | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_HEADER,0); | |
curl_setopt($ch,CURLOPT_NOSIGNAL, 1); | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
$version = curl_version(); | |
if ($version["version"] < "7.16.2") { | |
curl_setopt($ch,CURLOPT_TIMEOUT,1); | |
} else { | |
curl_setopt($ch,CURLOPT_TIMEOUT_MS,300); | |
} | |
return curl_exec($ch); | |
} else { | |
return ''; | |
} | |
} | |
$res = json_decode(simple_curl('http://weibo.com/'), true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment