使用消息队列与使用PHP的普通Cron作业之间的区别

时间:2022-01-26 08:01:43

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.

我们有一个构建在PHP上的大型web应用程序。这个应用程序允许调度tweet和wall post,并且有从服务器发出的计划邮件。

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.

所谓“计划”,我的意思是这些是PHP脚本,计划在特定时间使用cron运行。完成上述任务的PHP文件大约有7个。

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?

我听说过消息队列。有人能解释一下消息队列是否最适合这个场景吗?消息队列执行PHP脚本吗?还是我们需要完全不同的配置?有什么优点/缺点?

1 个解决方案

#1


5  

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进行异步任务(从PHP代码中异步)是一种基本的方法,使用作业/任务队列管理器是一种很复杂的方法,它可以为您提供更多的控制、功能和可伸缩性/弹性。

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.

Crontab很容易处理,但没有提供很多功能。它最好用于计划作业,而不是异步任务。

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.

另一方面,部署任务队列(及其消息代理)需要更多的时间。您必须首先选择正确的工具,然后学习如何在PHP代码中实现它们。但这是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.

感谢上帝,我没有使用PHP,而是在Python项目上与芹菜(与RabbitMQ耦合)一起玩;我确信您可以在PHP世界中找到类似的东西。

#1


5  

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进行异步任务(从PHP代码中异步)是一种基本的方法,使用作业/任务队列管理器是一种很复杂的方法,它可以为您提供更多的控制、功能和可伸缩性/弹性。

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.

Crontab很容易处理,但没有提供很多功能。它最好用于计划作业,而不是异步任务。

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.

另一方面,部署任务队列(及其消息代理)需要更多的时间。您必须首先选择正确的工具,然后学习如何在PHP代码中实现它们。但这是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.

感谢上帝,我没有使用PHP,而是在Python项目上与芹菜(与RabbitMQ耦合)一起玩;我确信您可以在PHP世界中找到类似的东西。