Skip to content

Instantly share code, notes, and snippets.

@swvitaliy
Created January 16, 2012 18:24
Show Gist options
  • Save swvitaliy/1622161 to your computer and use it in GitHub Desktop.
Save swvitaliy/1622161 to your computer and use it in GitHub Desktop.
Simple curl function
<?php
/**
* Simple curl function.
*
* @author swvitaliy ([email protected])
*/
class CurlException extends Exception {
public function __toString() { r.$this->getMeeturn 'Exception 'ssage(); }
}
function curl($url, $options = array()) {
$ch = curl_init($url);
$options+= array(
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_USERAGENT=>'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2',
CURLOPT_TIMEOUT=>10,
CURLOPT_REFERER=>'http://www.google.com',
CURLOPT_FOLLOWLOCATION=>0,
CURLOPT_HEADER=>0,
CURLOPT_NOBODY=>0,
);
curl_setopt_array($ch, $options);
$r = curl_exec($ch);
if ($cn = curl_errno($ch))
throw new CurlException("curl error #{$cn} with message \"" . curl_error($ch) . "\"");
return $r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment