如何优化我的FQL以避免Facebook超时? [英] How can I optimize my FQL to avoid Facebook timeouts?

查看:94
本文介绍了如何优化我的FQL以避免Facebook超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们进行一个简单的FQL查询,以获取自昨天以来用户的朋友共享的所有链接:

Let's take a simple FQL query to get all links shared by a user's friends since yesterday for example:

SELECT link_id, title, url, owner, created_time
FROM link
WHERE
    created_time > strtotime('yesterday') AND
    owner IN (
        SELECT uid2 FROM friend WHERE uid1 = me()
    )
LIMIT 100

如果用户有50个朋友,这将完美执行.但是,如果用户有数百个朋友,Facebook经常会返回错误.

If a user has 50 friends, this will execute perfectly. But if a user has hundreds of friends, more often than not Facebook returns an error.

选项:

  1. 将朋友选择查询限制为50 -当然可以,但是每次都会显示相同的朋友.除非您只需要常春藤盟国提要,否则这样做不是很有帮助.
  2. 批处理查询-使用偏移量创建一批查询并将每个查询限制为50个.不幸的是,这里也没有任何改进.
  3. 循环播放-到目前为止,这是我找到的最好的.遍历为批处理查询构建的相同查询,但一次通过多个api fql查询调用一次执行.但这什至是命中注定的.
  1. Limit the friend select query to 50 -- Sure, that will work, but it will show the same friends every time. Unless you want an Ivy League-only feed, this isn't very helpful.
  2. Batch Queries -- Create a batch of queries using offsets and limit each to 50. Unfortunately there's no improvement here either.
  3. Loop It -- So far this is the best I've found. Loop through the same queries you built for a batch query, but do it one at a time with multiple api fql query calls. But even this is hit and miss.

我如何适当地查询Facebook以确保获得成功?

How can I query Facebook appropriately to ensure successful results?

注释:

  • 我正在使用最新的Facebook php sdk 3.1.1
  • 我还尝试了扩展base_facebook.php中卷曲超时的默认选项

与超时相关的常见错误:

1.

Fatal error:  Uncaught Exception: 1: An unknown error occurred thrown in /..../facebook/php-sdk/src/base_facebook.php on line 708

第708行是一个异常错误:

line 708 is an exception error:

// results are returned, errors are thrown

if (is_array($result) && isset($result['error_code'])) { 
    throw new FacebookApiException($result);
}

2.

Fatal error: Uncaught CurlException: 52: SSL read: error:00000000:lib(0):func(0):reason(0), errno 104 thrown in /..../facebook/php-sdk/src/base_facebook.php on line 814

推荐答案

您应该像您所说的那样使用限制/偏移量进行循环,或者按照puffpio的建议预先缓存好友列表.

You should loop through using limit/offset like you said, or cache the friends list up front as puffpio suggested.

您说它仍然不能可靠地工作-这是因为某些用户可能有很多很多链接,而其他用户却没有那么多链接.另请注意,您可能正在为某些用户检索未缓存的数据.我建议您在循环中对失败的查询进行一次重试-通常是第一个超时,而第二个由于新缓存的数据而成功.

You said that it still wasn't working reliably - this is because some users may have many, many links, while others not so many. Note also that you may be retrieving uncached data for some users. I would recommend having a single retry in your loop for failed queries - it's often the case that the first one will time out and the second one will succeed due to newly cached data.

最后,对于后代,我要打开一个任务来优化链接表,以便在按时间过滤链接表时做得更好.

Finally, for posterity, I'm opening a task to optimize the link table to do a better job of being efficient when it's being filtered by time.

这篇关于如何优化我的FQL以避免Facebook超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆