Push notifications in PHP using Amazon SNS/SQS?

前端 未结 1 1718
臣服心动
臣服心动 2020-12-30 08:24

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

相关标签:
1条回答
  • 2020-12-30 09:02

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

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题