Last active
August 29, 2015 14:01
-
-
Save phluid61/a830af44fdce94345135 to your computer and use it in GitHub Desktop.
curl_get_contents -- if your jerk ISP disables allow_url_fopen
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
<?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