Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过使用pm2与(*)共享的我的ViewComposer执行队列作业而不使用paasing 正在尝试使用pm2防止队列作业通过laravel中的ViewComposer传递。_Laravel_Queue_Traits_Jobs_Pm2 - Fatal编程技术网

通过使用pm2与(*)共享的我的ViewComposer执行队列作业而不使用paasing 正在尝试使用pm2防止队列作业通过laravel中的ViewComposer传递。

通过使用pm2与(*)共享的我的ViewComposer执行队列作业而不使用paasing 正在尝试使用pm2防止队列作业通过laravel中的ViewComposer传递。,laravel,queue,traits,jobs,pm2,Laravel,Queue,Traits,Jobs,Pm2,问题:setCookie尚未应用,因为(我认为)没有来自外部调用访问(pm2)的会话 让我解释一下: 还与您共享我的应用程序的这一部分 我有一个队列作业,可以发送动态电子邮件(模板和邮件参数) 在我的ServiceController中, 另外,我在返回任何视图时,都会与所有视图共享所需的数据, 因此,我创建了一个ViewComposer,由AppServiceProvider中的任意视图(*)调用,在这个ViewComposer中,我也使用了一个使用许多特征的特征来收集视图所需的数据 当我在

问题:setCookie尚未应用,因为(我认为)没有来自外部调用访问(pm2)的会话

让我解释一下: 还与您共享我的应用程序的这一部分

我有一个队列作业,可以发送动态电子邮件(模板和邮件参数) 在我的ServiceController中, 另外,我在返回任何视图时,都会与所有视图共享所需的数据, 因此,我创建了一个ViewComposer,由AppServiceProvider中的任意视图(*)调用,在这个ViewComposer中,我也使用了一个使用许多特征的特征来收集视图所需的数据

  • 当我在应用程序中导航时,一切看起来都很好

  • 在执行任何使用排队作业的任务时,在我的情况下,发送电子邮件:

    当我运行php artisan queue:work时,一切都很好,我收到电子邮件

但是
  • 当我使用pm2 deamon调用该队列时,它会触发一个异常: (setCookie尚未应用)与我在ViewComposer中使用的特性相关
我知道我很难解释,但我真的需要一些帮助

这是我的密码:
  • pm2路径:/(服务器根目录)
  • 应用程序路径:/prod

  • 与ssh共享主机

1.应用服务提供商 2.网站作者: 3.作曲大师: 4.服务控制器: (流程的开始) 5.GuestMailerJob: 6.访客: 7.pm2执行文件:mail-worker.yml 8:手工清洁 9:pm2配置: 10-pm2状态: 它使用的是php artisan队列:工作/侦听 但pm2是个例外

pm2结果: Whoops\Run::handleError(“尚未应用特征方法setCookie,
/app_base_path/PRODMAAN/vendor/filp/whoops/src/whoops/Run.ph x 呜呜声\Run::handleShutdown()[内部]:0

失败的\u作业结果: Illumb\Queue\MaxAttemptSexceedException:App\Jobs\GuestMailerJob尝试次数太多或运行时间太长。该作业以前可能已超时

有什么问题? 谢谢你对代码结构的任何建议

    use Illuminate\Support\ServiceProvider;
    use Illuminate\Support\Facades\Schema;

    class AppServiceProvider extends ServiceProvider
    {
       public function register()
       {
         Schema::defaultStringLength(191);
       }

       public function boot()
       {
          view()->composer('*',
          'App\Http\ViewComposers\MasterComposer');
       }
    }
    namespace App\Http\ViewComposers;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Cache;
    use App\Website;
    use other_traits;

     trait WebsiteComposer 
     {
        use other_traits;
       protected function Get_Website(Request $request) 
       {
         //some code by calling other traits;
         // $results= get client websitestuff;

         $this->website= $results;

       }
     }         
     namespace App\Http\ViewComposers;
     use Illuminate\View\View;
     use Illuminate\Http\Request;

     class MasterComposer
     {
        use WebsiteComposer; 
        public $web=[];

        public function __construct()
        {
        }

        public function compose(View $view)
        { 
          //to prevent external views( email templates located in 
          //views/emails from passing by getting website process...

           if(!starts_with($view->getName(), 'emails'))
           {
             //here where exception fired using pm2 

             $this->Get_Website(request());
             $this->web=$this->website;
           }

           View::share('website', $this->web);
        }
      }
       // POST PROCESS then Calling this function :

       public function EmailDispatcher($data,Request $request)
       {
          //some code...
          dispatch(function () use ($data) {
          dispatch(new GuestMailerJob($data));
          });

         return redirect('somview');
       }
   namespace App\Jobs;
   use App\Mail\GuestMailer;
   // needed uses...

   class GuestMailerJob implements ShouldQueue
   {
     use Dispatchable, InteractsWithQueue, Queueable, 
     SerializesModels,GuestMailer;

       protected $data;
       public $tries = 3;
       public $timeout = 10;

       public function retryUntil()
       {
          return now()->addSeconds(12);
       }

       public function __construct(Array $data)
       {
          $this->data=$data;
       }

       public function handle()
       {
          $this->sendEmail($this->data);
       }
   }
   namespace App\Mail;
   use Illuminate\Http\Request;
   use Mail;

   trait GuestMailer 
   {
      protected function sendEmail(array $all) 
      { 
          $toview = array( 

            'title' => $all["title"],
            'other_attributes' => $all["other_attributes"]
          );

           Mail::send( [$all["template"]=> $all['view']],$toview,

           function ($message)  use($all)
           { 
             $message->from( $all['from'],$all['nameFrom'] );
             $message->subject( $all['subject'] );
             //other params...
            }

          });
      }
    }
         //located in: (/prod)
         //mail-worker.yml content:


           apps:
             - name: mail-worker
             script: artisan
             exec_mode: fork
             interpreter: php
             instances: 1
           args:
             - queue:work
             - --tries=1
             - --sleep=1
       all php artisan cleaners are implemented

       ex : php artisan clear-compiled
            php artisan queue:restart
           pm2 start mail-worker.yml
           pm2 monit
       id    name            mode   reload   status   cpu   memory

       0     mail-worker     fork   1        online   0%    6.5mp