From f04edb840646369e3aa095dc2cb69074842b2f2a Mon Sep 17 00:00:00 2001 From: Mitchell McKenna Date: Mon, 18 Feb 2013 03:40:58 -0800 Subject: [PATCH] Replace file_get_contents() with Curl - Replace file_get_contents() with Curl because Curl is faster and file_get_contents() is disabled on a lot of servers for security reasons. - I also notice Curl getting a lot of results back from websites where file_get_contents() didn't work. --- OpenGraph.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/OpenGraph.php b/OpenGraph.php index ee7cce8..6ef941b 100644 --- a/OpenGraph.php +++ b/OpenGraph.php @@ -47,7 +47,21 @@ class OpenGraph implements Iterator * @return OpenGraph */ static public function fetch($URI) { - return self::_parse(file_get_contents($URI)); + $curl = curl_init($URI); + + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); + + $response = curl_exec($curl); + + curl_close($curl); + + return self::_parse($response); } /**