安排推文 PHP 和 Cron
我正在构建一个 Twitter 应用程序,用户可以在其中输入推文并安排其发布一次、每天、每周或每月。为该操作实施 cron 作业的最佳方法是什么?我只能想到每分钟运行一个 cron 作业并匹配时间和日期 - 这不可能是最好的解决方案,因为它会给服务器带来很大的压力。我正在用 ubuntu 运行一个灯栈 - 任何建议将不胜感激。
I am building a twitter application where a user can enter a tweet and can schedule it to be posted once, daily, weekly, or monthly. What is the best way to implement a cron job for this action? I can only think of running a cron job every minute and matching up the times and dates - this can't be the best solution as it would place a lot of stress on the server. I am running a lamp stack with ubuntu - any suggestions would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 crontab,则需要为计划选项的每个变体(每日、每周、每月)创建 crontab 条目。为每个条目运行的脚本需要为选择该调度频率的所有用户执行工作。
Crontab 文件遵循通用格式。从 crontab(5) 手册页:
0 0 * * *
0 0 * * 0
0 0 1 * *
If you're using crontab, you'll need to create crontab entry for each variation of scheduling options (daily, weekly, monthly). The script run for each entry would need to perform the work for all users opted into that scheduling frequency.
Crontab files follow a general format. From the crontab(5) man page:
0 0 * * *
0 0 * * 0
0 0 1 * *
如果最低间隔是每天一次,那么每分钟执行一次的 cronjob 可能有点矫枉过正。另一方面,每分钟执行一次查询的脚本对网络服务器来说并不是太大的压力,因为它可能在相对低端的服务器上每分钟处理 1000 个查询。
当您的应用程序/网站将被大量使用时,您可以开始进行更多优化,但是当您的网站/应用程序变得那么大时,可能需要每分钟运行它:)。
A cronjob that is executed every minute is perhaps a bit of overkill if the lowest interval is once a day. On the other hand, a script that does a query every minute isn't that much of a strain on a webserver as it probably can handle 1000 queries a minute on a relative low end server.
When your appliaction/website wil be used a lot you could starting about more optimalisation, but when your website/application gets that big, it is probably needed to run it every minute :).
我不知道具体是如何做到的,但是 unix 中有一个可以使用的命令: http://en.wikipedia.org/wiki/At_%28Unix%29
I don't know exactly how it could be done, but there is this command in unix which could be used : http://en.wikipedia.org/wiki/At_%28Unix%29