-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why not use curl instead ? #4
Comments
I've used cURL in my fork if you like. |
Well, actually, I don't know why, but a lot of websites don't let you parse the contents using cURL... I tried to use this cURL funtion to get the contents from http://nytimes.com, as an example, and I just can't... nonetheless with the regular file_get_contents I was succesful retrieving the open graph... cURL could be faster, but the file_get_contents by now is handling a greater range of websites in my point of view.. |
That's interesting. I wonder if there's any options that could be passed with cURL to change that. Maybe they try to prevent scraping so if a user agent or something was passed with the request maybe for example. |
in pull request #8, with the cURL options I have set, I have found I actually am getting more results back with cURL than file_get_contents(). nytimes.com worked fine. I did notice some websites required a user-agent to be set, they didn't seem to care what it's set to, just as long as it was set, so I set it to |
Hi Guys, $user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36'; Result is always: What workarounds/tricks have resolved this for you? |
Simple change... A lot more compatible, and far less compatibility issues than file_get_contents (allow_url_fopen must be on, other issues I couldn't even sort out on fetching remote content via file_get_contents() on my production server)...
Just a suggestion, as I made the change on my own and things work fine for me now.
/**
* Fetches a URI and parses it for Open Graph data, returns
* false on error.
*
* @param $URI URI to page to parse for Open Graph data
* @return OpenGraph
*/
static public function fetch($URI) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URI);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
curl_close($ch);
return self::_parse($contents);
}
The text was updated successfully, but these errors were encountered: