<i id='4udXB'><tr id='4udXB'><dt id='4udXB'><q id='4udXB'><span id='4udXB'><b id='4udXB'><form id='4udXB'><ins id='4udXB'></ins><ul id='4udXB'></ul><sub id='4udXB'></sub></form><legend id='4udXB'></legend><bdo id='4udXB'><pre id='4udXB'><center id='4udXB'></center></pre></bdo></b><th id='4udXB'></th></span></q></dt></tr></i><div id='4udXB'><tfoot id='4udXB'></tfoot><dl id='4udXB'><fieldset id='4udXB'></fieldset></dl></div>

        <tfoot id='4udXB'></tfoot>
      1. <small id='4udXB'></small><noframes id='4udXB'>

        • <bdo id='4udXB'></bdo><ul id='4udXB'></ul>
        <legend id='4udXB'><style id='4udXB'><dir id='4udXB'><q id='4udXB'></q></dir></style></legend>

        如何让函数在 Laravel 的后台运行

        How to make function run in background in laravel(如何让函数在 Laravel 的后台运行)
      2. <i id='RJkbq'><tr id='RJkbq'><dt id='RJkbq'><q id='RJkbq'><span id='RJkbq'><b id='RJkbq'><form id='RJkbq'><ins id='RJkbq'></ins><ul id='RJkbq'></ul><sub id='RJkbq'></sub></form><legend id='RJkbq'></legend><bdo id='RJkbq'><pre id='RJkbq'><center id='RJkbq'></center></pre></bdo></b><th id='RJkbq'></th></span></q></dt></tr></i><div id='RJkbq'><tfoot id='RJkbq'></tfoot><dl id='RJkbq'><fieldset id='RJkbq'></fieldset></dl></div>

            1. <tfoot id='RJkbq'></tfoot>
              <legend id='RJkbq'><style id='RJkbq'><dir id='RJkbq'><q id='RJkbq'></q></dir></style></legend>

              <small id='RJkbq'></small><noframes id='RJkbq'>

                <bdo id='RJkbq'></bdo><ul id='RJkbq'></ul>

                  <tbody id='RJkbq'></tbody>
                • 本文介绍了如何让函数在 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 :

                  php artisan queue:table
                  
                  php artisan migrate
                  

                  然后创建要添加到队列中的作业

                  then create the Job that you want to add to the queue

                  <?php
                  
                  namespace AppJobs;
                  
                  use AppUser;
                  use AppJobsJob;
                  use IlluminateContractsMailMailer;
                  use IlluminateQueueSerializesModels;
                  use IlluminateQueueInteractsWithQueue;
                  use IlluminateContractsBusSelfHandling;
                  use IlluminateContractsQueueShouldQueue;
                  
                  class SendEmail extends Job implements SelfHandling, ShouldQueue
                  {
                      use InteractsWithQueue, SerializesModels;
                  
                      protected $user;
                  
                      public function __construct(User $user)
                      {
                          $this->user = $user;
                      }
                  
                      public function handle(Mailer $mailer)
                      {
                          $mailer->send('emails.hello', ['user' => $this->user], function ($m) {
                              //
                          });
                      }
                  }
                  

                  然后在控制器中调度作业

                  then in the Controller dispatch the job

                  <?php
                  
                  namespace AppHttpControllers;
                  
                  use AppUser;
                  use IlluminateHttpRequest;
                  use AppJobsSendReminderEmail;
                  use AppHttpControllersController;
                  
                  class UserController extends Controller
                  {
                      /**
                       * Send a reminder e-mail to a given user.
                       *
                       * @param  Request  $request
                       * @param  int  $id
                       * @return Response
                       */
                      public function sendReminderEmail(Request $request, $id)
                      {
                          $user = User::findOrFail($id);
                  
                          $sendEmailJob = new SendEmail($user);
                  
                          // or if you want a specific queue
                  
                          $sendEmailJob = (new SendEmail($user))->onQueue('emails');
                  
                          // or if you want to delay it
                  
                          $sendEmailJob = (new SendEmail($user))->delay(30); // seconds
                  
                          $this->dispatch($sendEmailJob);
                      }
                  }
                  

                  为此,您需要运行队列侦听器:

                  For that to work, you need to be running the Queue Listener:

                  php artisan queue:listen
                  

                  这能回答吗?

                  这篇关于如何让函数在 Laravel 的后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                • <i id='ffuzc'><tr id='ffuzc'><dt id='ffuzc'><q id='ffuzc'><span id='ffuzc'><b id='ffuzc'><form id='ffuzc'><ins id='ffuzc'></ins><ul id='ffuzc'></ul><sub id='ffuzc'></sub></form><legend id='ffuzc'></legend><bdo id='ffuzc'><pre id='ffuzc'><center id='ffuzc'></center></pre></bdo></b><th id='ffuzc'></th></span></q></dt></tr></i><div id='ffuzc'><tfoot id='ffuzc'></tfoot><dl id='ffuzc'><fieldset id='ffuzc'></fieldset></dl></div>

                  <tfoot id='ffuzc'></tfoot>
                      <bdo id='ffuzc'></bdo><ul id='ffuzc'></ul>

                        <legend id='ffuzc'><style id='ffuzc'><dir id='ffuzc'><q id='ffuzc'></q></dir></style></legend>

                        1. <small id='ffuzc'></small><noframes id='ffuzc'>

                            <tbody id='ffuzc'></tbody>