如何让函数在 Laravel 的后台运行
问题描述
我正在 Laravel 5.0 中开发一个网站,并在 Windows Server2012 中托管.
I am developing a website in Laravel 5.0 and hosted in Windows Server2012.
我遇到了一个问题,即我正在从另一个函数 A 调用控制器中的函数 B 并且我希望调用另一个函数 B 的函数 A 不等待函数 B 的完成.而Function B获取后台完成页面的独立表单用户终止和函数A返回.
I am stuck at a problem which is I am calling a function B in controller from another function A and I want that the function A which calls the another function B does not wait for the completion of function B . And Function B gets completes in the background and independent form user termination of page and function A return .
我搜索了这个,发现这可以通过像 windows 中的作业、pcntl_fork() 和 laravel 中的队列功能的 cron 来实现.我是这一切的初学者.
I have searched this and found that this can be implemented through cron like jobs in windows, pcntl_fork() and Queue functionality in laravel. I am beginner in all this.
请帮忙!提前致谢.
推荐答案
如文档所述 http://laravel.com/docs/5.1/queues,首先你需要设置驱动程序——我一开始会去数据库:
as the documentation states http://laravel.com/docs/5.1/queues, first you need to setup the driver - i would go for database in the beginning :
然后创建要添加到队列中的作业
then create the Job that you want to add to the queue
然后在控制器中调度作业
then in the Controller dispatch the job
为此,您需要运行队列侦听器:
For that to work, you need to be running the Queue Listener:
这能回答吗?
这篇关于如何让函数在 Laravel 的后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!