Skip to content

Instantly share code, notes, and snippets.

@stojg stojg/curl.php
Last active Aug 29, 2015

What would you like to do?
simple curl template
function get($url) {
$timeout = 2;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if (curl_error($ch)) {
printf("%s\ncurl error: %s".PHP_EOL, $url, curl_error($ch));
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($code != 200) {
printf("non 200 response: %d".PHP_EOL.'%s'.PHP_EOL, $code, $result);
return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.