创建 twitter 之类的提及或使用 php 召集 [英] create mention like twitter or convore with php

查看:15
本文介绍了创建 twitter 之类的提及或使用 php 召集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我只是好奇.关于他们如何做事.我假设他们做这样的事情

hello im just curious. about how they do stuff. what i assume they do something like this

@someone1 im stacking on stackoverflow RT @someone2 : hello guys what are you doing?

在我用我的方式做之前,我想告诉你我的数据库方案

before i do it in my way i want to tell you about my database scheme

// CID = COMMENT ID, BID  = BLOG ID, UID = USER ID
CID    BID   UID    COMMENT
1       1     1      @someone1 im stacking on stackoverflow RT @someone2 : ....
2       1     4      @someone1 im stacking on stackoverflow RT @someone2 : ....
3       1     12     @someone1 im stacking on stackoverflow RT @someone2 : ....

  1. 他们使用正则表达式来取@someones 名称

  1. they use regex to do like this to take the @someones name

preg_match_all("/@[a-zA-Z0-9_]+/", $text, $matches);

  • 然后他们把@去掉每个名字

  • then they get the @ off each name

    foreach ($matches as $value) {
    foreach ($value as $value) {
        $usernames[] = substr($value, 1);
    }
    }
    

  • 然后他们通过做这样的事情从数据库中获取 UID

  • then they get the UID from the database from doing something like this

    foreach ($username as $value) {
    # insert database one by one ? so it will be like the example above
    }
    

  • 然后我们可以输出评论buy获取UID.

    then we can just output the comment buy geting the UID.

    然后我们可以获取博客中的所有评论.(没有相同的评论)where blog buid = 1 并通过where uid = :uid 向他们通知每个用户.

    then somhow we can get all the comments in the blog. ( without a same comment ) where blog buid = 1 and give them an notification on every user by where uid = :uid.

    有没有更好的方法来做到这一点?诸如 twitter 或 convore 之类的东西?

    感谢收看

    亚当斋月

    推荐答案

    我使用我们用于通信的内部应用程序做了类似的事情.

    I have done something similar to this with an in-house application that we use for communication.

    基本上,您将有两个表:status_updatesmentions.每个状态更新都有很多提及.每当有人创建状态更新时,您将其保存到 status_updates 表中.在此过程中,您还可以使用 Regex 检测任何 @username 提及".当您找到提及时,将其添加到您的 mentions 表中.例如,您的 mentions 表可能如下所示:

    Basically, you are going to have two tables: status_updates and mentions. Each status update has many mentions. Whenever someone creates a status update, you save it to the status_updates table. During this process, you can also use Regex to detect any @username "mentions". When you find a mention, you add it to your mentions table. For example, your mentions table might look something like this:

     mention_id (Auto-incrementing key) | status_message_id | username_id
    

    这样,如果您想查看状态消息中是否提到某人,您可以在 status_messages 表中进行快速查找,而不是每次加载状态消息并运行 Regex.这种方法的另一个好处是它允许您在每个状态消息中多次提及.只需在 mentions 中为每个创建一个记录.

    That way if you want to see if someone is mentioned in a status message you can do a quick lookup in the status_messages table, as opposed to loading up the status message and running the Regex each time. The other nice thing about this approach is that it allows you to have multiple mentions in each status message. Just create a record in mentions for each.

    这是我们设置它的基本方式.

    That's the basic way that we have set it up.

    如果您想为给定用户拉取活动提要",仅显示他们被提及的状态更新,则很简单:

    If you wanted to pull an "activity feed" for a given user, showing only the status updates in which they have been mentioned, it would be as simple as:

    SELECT * FROM mentions m LEFT JOIN status_messages s ON m.status_message_id = s.id WHERE m.username_id = $username_id
    

    我应该指出,他们在 Twitter 上不是这样做的,因为他们正在处理规模问题,这将使这种简单的做事方式变得不可能.但是,如果您不担心扩展到数十万用户,我认为这是最简单的解决方案.如果是,那么您手头上的问题可能比这更多.

    I should note that this is not how they do it at Twitter, because they are dealing with issues of scale that would make this simple way of doing things impossible. However, I think this is the simplest solution that works well if you aren't worried about scaling to hundreds of thousands of users. If you are, then you probably have more issues on your hands than this.

    这篇关于创建 twitter 之类的提及或使用 php 召集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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