在 PHP 中使用消息队列与普通 Cron 作业之间的区别
我们有一个基于 PHP 构建的大型 Web 应用程序。该应用程序允许安排推文和墙贴,并且有从服务器发出的预定电子邮件。
我所说的“计划”是指这些 PHP 脚本计划使用 cron
在特定时间运行。大约有 7 个 PHP 文件可以完成上述工作。
我一直听说消息队列。谁能解释一下消息队列是否最适合这种情况?消息队列执行 PHP 脚本吗?或者我们是否需要完全不同地配置它?有什么优点/缺点?
We have a large web application built on PHP. This application allows scheduling tweets and wall posts and there are scheduled emails that go out from the server.
By 'scheduled', I mean that these are PHP scripts scheduled to run at particular time using cron
. There are about 7 PHP files that do the above jobs.
I have been hearing about Message Queues. Can anyone explain if Message Queues are the best fit in this scenario? Do Message Queues execute PHP scripts? or do we need to configure this entirely differently? What are the advantages / disadvantages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Crontab来创建异步任务(与PHP代码异步)是一种基本方法,而使用作业/任务队列管理器是一种复杂的方法并为您提供更多的控制权、能力和可扩展性/弹性。
Crontab 很容易处理,但没有提供很多功能。它最适合计划作业而不是异步任务。
另一方面,部署任务队列(及其消息代理)需要更多时间。您必须首先选择正确的工具,然后学习如何在 PHP 代码中实现它们。但这是 2011 年要走的路。
谢天谢地,我不使用 PHP,但玩过 Celery (与
RabbitMQ
结合使用)在 Python 项目上;我相信您可以在 PHP 世界中找到类似的东西。Using Crontab to make asynchronous tasks (asynchronous from your PHP code) is a basic approach where using a job/task queue manager is an elaborate one and give you more control, power and scalability/elasticity.
Crontab are very easy to deal with but does not offer a lot of functionalities. It is best for scheduled jobs rather than for asynchronous tasks.
On the other hand, deploying a Task queue (and its message broker) require more time. You have to choose the right tools first then learn how to implement them in your PHP code. But this is the way to go in 2011.
Thank God, I don't do PHP but have played around with Celery (coupled with
RabbitMQ
) on Python projects ; I am sure you can find something similar in the PHP world.