Whether using the Facebook PHP SDK, or just loading data using curl with $contents = file_get_contents("https://graph.facebook.com/$id?access_token=$accessToken")
, it takes around a whole second for the response to come.
That counts as very slow when I need to check the data for a bunch of ids.
When in a browser, if I type in a facebook graph url, I get the results almost instantly, under a tenth of the time it takes in PHP.
What is causing this problem, and how can I make it as fast as it would be in any browser? I know the browser can do it. There has to be a way to make it fast in PHP too.
IDEA: perhaps I need to configure something in cURL?
What I have tried:
- Using the PHP SDK. It's as slow. The reason I tried using
file_get_contents()
in the first place was because I was hoping the PHP SDK wasn't configured properly. - Using
setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
. It didn't make a difference. AFTER ANSWER ACCEPT EDIT: actually, this together with reusing the curl handle made the subsequent requests really fast.
EDIT: here is a pastebin of the code I used to measure the time it takes to do the requests: http://pastebin.com/bEbuqq5g. I corrected the text that used to say microseconds, to seconds. this is what produces results similar to the one I wrote in my comment in this question: Facebook graph extremely slow in PHP. Note also that they take similarly slow times even if the access token is expired, like in my pastebin example.
EDIT 2: there should be partly a problem with ssl. I tried benchmarking http://graph.facebook.com/4 (no httpS), and it resulted in 1.2 seconds for three requests, whereas the same, but with https took 2.2 seconds. This is in no way a solution though, because for any request that needs an access token, I must use https.
file_get_contents
and your browser. For the php script it first needs to parse that stuffs and get the content and give back to you. On the other hand it just send it on a fly.