Skip to content

Instantly share code, notes, and snippets.

@k1ic
Last active August 29, 2015 14:16
Show Gist options
  • Save k1ic/9cdf01f7e228b8387bf7 to your computer and use it in GitHub Desktop.
Save k1ic/9cdf01f7e228b8387bf7 to your computer and use it in GitHub Desktop.
a simple demo of curl
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