dougang6178 2015-03-14 04:18
浏览 27

调度系统 - 如何完成? PHP与Node.js

Consider the notification system in Google calendar. It sends you a push/email notification user specified time (like 10 minutes/10 hours etc). How is this implemented on the server side? Assuming Google calendar is on a PHP/Apache platform, is there a script which runs continuously and checks the current time against the time in database and then push notifications when the times match? Basic question - how does the server know when to push the notifications?

Is it easier to do this on Apache/PHP or Node.js?

  • 写回答

2条回答 默认 最新

  • duan0714 2015-03-14 05:43
    关注

    You are asking about black magic. Are you sure you want to know the answer?

    In answer your hypothetical question, "If Google uses PHP for scheduled notifications how do they do it?" the best answer would be cron. It really has nothing to do with PHP, it is a service run by the operating system (at least on *nix-based systems) which wakes up every minute, checks a to-do list, runs things it needs to run, and then goes back to sleep. The "minute" thing is a very important detail: it doesn't run constantly, it doesn't run tasks with a by-the-second precision, only every minute.

    Cron can run any executable script, and is designed to run with the permissions of the person who scheduled the cron task, so it can run shell scripts out of your home directory and it can run php scripts if they are correctly configured.

    As an alternative to cron, one could also write a new service that continually runs as a daemon, which wakes up every so often to check if notifications need to be sent. You would lose the standardized behavior of cron, but you could do by-the-second scheduling, and anything else your heart desires.

    As for knowing when to send notifications, you create a database containing a list of tasks and when they should run, and then find a nicely optimized query to grab the current set and process them. Cron, or your custom service (which you have written in Node.js because all the cool kids are using Node.js), runs this query every minute / every so many seconds. And if you are Google, you then figure out how to scale this out to a thousand machines.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据