Symfony2和后台进程(Symfony2 and Background processes)

编程入门 行业动态 更新时间:2024-10-17 05:31:35
Symfony2和后台进程(Symfony2 and Background processes)

我在Symfony 2.3项目中有一个类正在做一些http请求,需要一些时间。

我想将此任务作为后台进程运行,以便服务器向客户端返回一个答案,后台进程将继续运行。

你知道如何在Symfony中做到这一点?

我发现过程组件: http : //symfony.com/doc/current/components/process.html但我不确定是否可以从那里运行类方法。

I have a class in my Symfony 2.3 project that is doing some http requests and takes some time.

I would like to run this task as a background process, so that the server returns an answer to the client and the background process continues running.

Do you know how to do that in Symfony?

I found the Process Component: http://symfony.com/doc/current/components/process.html but I am not sure if I can run a class method from there.

最满意答案

一个简单的方法是通过使用一个队列和一个symfony命令来处理队列,从而将繁重的工作与响应分开。

http://symfony.com/doc/current/components/console/introduction.html

创建一个处理添加到队列中的作业的symfony命令,然后将要完成的工作添加到控制器的队列中。 该队列可能会作为作业的数据库表来实施。

这样,您可以将成功响应返回给用户,并定期在服务器上运行cron作业,以处理您所需的工作。

A simple way to do this is to separate the heavy lifting from the response by using a queue and a symfony command to process the queue.

http://symfony.com/doc/current/components/console/introduction.html

Create a symfony command that processes the jobs added to a queue, then add the work to be done to the queue from your controller. The queue will probably be implemented as a database table of jobs.

That way you can return a success response to the user and run a cron job on the server regularly to process the work you require.

更多推荐

本文发布于:2023-07-22 09:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   进程   Background   processes

发布评论

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

>www.elefans.com

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