Skip to content

Commit

Permalink
Merge pull request #8 from MitchellMcKenna/feature/replace-file_get_c…
Browse files Browse the repository at this point in the history
…ontents-with-curl

Replace file_get_contents() with cURL for speed/security
  • Loading branch information
scottmac committed Feb 18, 2013
2 parents 7fc9bf1 + f04edb8 commit b403cf2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit b403cf2

Please sign in to comment.