Skip to content

Instantly share code, notes, and snippets.

@phluid61
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phluid61/a830af44fdce94345135 to your computer and use it in GitHub Desktop.
Save phluid61/a830af44fdce94345135 to your computer and use it in GitHub Desktop.
curl_get_contents -- if your jerk ISP disables allow_url_fopen
<?php
function curl_get_contents($url) {
$ch = curl_init($url);
# curl options
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
# socket options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
# query
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_ENCODING, '');
# invoke curl, get response body
$result = curl_exec($ch);
if ($result === FALSE) {
error_log("cURL Error [".curl_errno($ch)."]: ".curl_error($ch).". URL = ".var_export($url,1));
}
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment