PHP中不同请求的单独任务会更快吗?(Seperate task in different request will be faster in PHP?)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
PHP中不同请求的单独任务会更快吗?(Seperate task in different request will be faster in PHP?)

说我收到了执行5个任务的请求。 哪个会更快?

完成此请求中的所有5个任务。

再发送5个HTTP请求来单独执行5个任务。 (我不确定在PHP中发送HTTP任务是否合适。但我不知道如何在本地执行它们,我需要在我的框架中编写代码)

额外信息:我正在做一个定时任务系统。 任务将存储在DB中,我会让某人每分钟触发一次主控制器来执行准时任务。

额外需求:如果您对设计有任何建议,我很高兴能够开悟!

Say I received a request to perform 5 task. Which will be faster?

Do all 5 tasks in this request.

Send 5 more HTTP request to do the 5 tasks seperately. (I am not sure if sending HTTP quest in PHP is good. But I don't know how to do them locally and I need to write code in my framework)

Extra information : I am doing a timed task system. Tasks will be stored in DB, and I will have someone trigger the main controller every minute to perform the on-time task.

Extra demand : If you have suggestion on the design, I am happy to get enlightened!

最满意答案

如果您的任务繁重而且没有依赖性,那么首先,cronjob对您来说是一个很好的解决方案。 您可以设置每分钟运行的cronjob,并调用PHP脚本来执行任务。 您可能需要将状态记录到file / db中以进行监视。

您还可能需要一个状态标志来确保任务在执行时不重叠。

如果您正在寻找更可靠和“企业”的解决方案,您可以检查队列技术(RabbitMQ或Gearman ...)。

对于快速解决方案,5个任务的HTTP请求仍然很好,但您必须仔细管理状态(应用事务...)

If your tasks are heavy and no dependency, cronjob is a good solution for you as first. You may setup cronjob which runs every minute, and call PHP script to perform the task. You may need to log the status into file/db to monitor.

You also may need a status flag to make sure the tasks are not overlapped in performing.

If you are looking for more trustable and "enterprise" solutions, you can check queue technology (RabbitMQ or Gearman...).

For the quick solution, HTTP request for 5 tasks is still good, but you have to manage status carefully (apply transaction...)

更多推荐

本文发布于:2023-04-13 12:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d59feb7c2f0881f2a81583364b916e5a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更快   Seperate   PHP   faster   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!