How to do batch request of fql queries in graph api?

不打扰是莪最后的温柔 提交于 2019-12-21 06:34:53

问题


I am having 4-5 fql queries in single function. Each of them taking 2-4 seconds to execute. Total 14-15 seconds are required to execute that whole function. User required to wait for long time. So I want to reduce that processing time. ( There is not well supported multi-threading concept in PHP.)

I have heard of batch request concept in graph api. And I have googled a lot but didn't understand how to use batch request for fql queries in graph api.

  • Can anyone give explanation with example for using batch request of fql queries ?
  • By what time query processing time will reduce?
  • Is there any another method to reduce time of many fql queries?

回答1:


Instead of calling each FQL query separately, why not use FQL Multiquery?

http://developers.facebook.com/docs/reference/rest/fql.multiquery/

UPDATE Otherwise, if you don't want do use multiquery I think what you're looking for is here. I couldn't find anything more about FQL and Batch.

curl \
     -F 'access_token=…' \
     -F 'batch=[{ "method": "POST", \
    "relative_url": "method/fql.query?query=select+name+from+user+where+uid=4", \
     }]
https://graph.facebook.com



回答2:


Updated:

https://graph.facebook.com/?batch=[{"method":"GET","relative_url":"me"},{"method":"GET","relative_url":"me/friends?limit=50"}]&access_token=ACCESS_TOKEN&method=post

More info here: http://developers.facebook.com/blog/post/2011/03/17/batch-requests-in-graph-api/




回答3:


//$current_user=facebook id

 $query1="SELECT uid, name FROM user WHERE is_app_user=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user)";
 $query2="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user )";
 $query3="SELECT uid, name, work, education FROM user WHERE uid = $current_user";
 $queries = array(
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query1)),
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query2)),
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query3))
            );

            $objs = $facebook->api('/?batch='.json_encode($queries), 'POST');

$objs gets json array of whole result of thre queries.

And it is saving time a lot. This 3 queries individually takes total 9 seconds. With multiquery it takes 7 seconds. And with batch request it takes 3.6 seconds.



来源:https://stackoverflow.com/questions/9632277/how-to-do-batch-request-of-fql-queries-in-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!