本文介绍了按使用Amazon SNS / SQS在PHP通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的地盘我想要做像做#1意见推送通知。亚马逊SNS / SQS似乎提供了一个框架,要做到这一点,但我很难找到网络上的任何code /解释超出了一个Hello World相当于什么。

On my site I'd like to do push notifications of comments like Stackoverflow does. Amazon SNS/SQS seems to provide a framework to do this but I'm having difficulty finding any code/explanation on the web for anything beyond a "hello world" equivalent.

从阅读AWS SNS / SQS文档,它看起来像我需要以下内容:

From reading the AWS SNS/SQS documentation it looks like I need the following:

逻辑:

  1. 发表评论/回答一个新的问题
  2. 创建话题(对于第一个注释/只回答)
  3. 在发布消息
  4. 订阅话题

在页面上PHP在这里评论发布(http://mysite.com/postCommentOrAnswer.php):

PHP on the page where comments are posted (http://mysite.com/postCommentOrAnswer.php):

$comment=$_POST['comment']; //posted comment
require_once 'application/third_party/AWSSDKforPHP/sdk.class.php';
$sns = new AmazonSNS();

$response = $sns->create_topic('SO-like-question-12374940'); //create topic

$response = $sns->publish(
  'arn:aws:sns:us-east-1:9876543210:SO-like-question-12374940',
  $comment
);  //publish comment

$response = $sns->subscribe(
  'arn:aws:sns:us-east-1:9876543210:SO-like-question-12374940',
  'https ',
  'https://mysite.com/notificationsReceiver'
); // Subscribe to notifications

在那里收到通知的页面上PHP(http://mysite.com/notificationsReceiver.php):

PHP on the page where notifications are received (http://mysite.com/notificationsReceiver.php):

no idea, thoughts?

显然,这不是接近于一个完整的论证,可能有一些不正确的函数调用,但我不知道是否有人也许能帮助建立在这个?

Obviously, this is not close to being a complete demonstration and probably has some incorrect function calls but I was wondering if someone might be able to help build upon this?

推荐答案

您的评论暗示,你是不是拘泥于SQS,所以我回答了MySQL的解决方案。

Your comment implied that you are not wedded to SQS, so I am answering with a MySQL solution.

除非你处理这么多的流量的消息实际上永远得到排队,我建议只是一个简单的MySQL表的方法。

Unless you're dealing with so much traffic that messages would actually ever get queued, I'd recommend just a simple MySQL table approach.

我有一个MySQL的通知表,看起来像这样一个网站:

I have a site with a MySQL notifications table that looks like this:

CREATE TABLE `notification` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `user_id` INT(11) NOT NULL,
    `notification_type` ENUM('inline','popup') NOT NULL DEFAULT 'inline',
    `html` TEXT NOT NULL,
    `entered_date` DATETIME NOT NULL,
    `display_date` DATETIME NOT NULL,
    `show_once` TINYINT(1) NOT NULL DEFAULT '0',
    `closable` TINYINT(1) NOT NULL DEFAULT '1',
    `destroy_on_close` TINYINT(1) NOT NULL DEFAULT '1',
    PRIMARY KEY (`id`),
    INDEX `user_id` (`user_id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM

此表时页面加载检查并在适当的通知是根据通知数据显示。插入完成各种动作或事件发生在网站上。

This table is checked upon page load and the proper notification is displayed according to the notification data. Insertion is done as various actions or events occur on the website.

我在超过10,000个用户,到目前为止,这种方法还没有被证明是该网站的一个瓶颈。我不指望它在短期内,无论是。

I'm at well over 10,000 users and so far this approach has not proven to be a bottleneck for the site. I don't expect it to anytime soon, either.

这篇关于按使用Amazon SNS / SQS在PHP通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 12:58