dreamer2014520 2016-12-28 10:38 采纳率: 0%
浏览 45

Laravel 5.3队列无法在共享主机中工作

In my Laravel 5.3.* application, I am having queues running in the background. This works completely fine in my local machine. But when this is made live on the server (shared hosting), it doesn't work at all.

Here's the scenario:

  1. Administrator is submitting the admin generator form data.

  2. Data is getting inserted in the database.

  3. Shoot an email regarding the same.

So, in order to have this functionality going smoothly, I have created a cron job on my server's cPanel.

Here's the cron job:

/usr/local/bin/php /home/<username>/laravel-app/artisan schedule:run >/dev/null 2>&1

And here's the app/Console/Kernel.php file content

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    // $schedule->command('inspire')
    //          ->hourly();

    $schedule->command('queue:work --daemon --tries=3')
             ->everyMinute()
             ->withoutOverlapping();
}

And I have also created the database for jobs by running

php artisan queue:table;
php artisan queue:failed-table;
php artisan migrate;

When the administrator is generated/inserted, an event is fired:

event(new AdministratorHasBeenGenerated($user, $request->password));

which will send a welcome email to the provided email id (in app/Listeners/AdministratorHasBeenGenerated/SendWelcomeEmail.php)

/**
 * Handle the event.
 *
 * @param  AdministratorHasBeenGenerated  $event
 * @return void
 */
public function handle(AdministratorHasBeenGenerated $event)
{
    Mail::to($event->administrator->email)
          ->queue(new GeneratedMail($event->administrator, $event->password));
}

And here's the mail configs in the .env file

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=correct_username
MAIL_PASSWORD=correct_password
MAIL_ENCRYPTION=null

I don't receive any errors or things as such, but neither I receive any welcome email even though I provide correct email id.


UPDATE 1: 21st December, 2017

This is just a work around as I couldn't find the actual solution to this problem. What I did was I created another cron job for just running queues..

/usr/local/bin/php /home/<username>/laravel-app/artisan queue:work --daemon --tries=3 >/dev/null 2>&1

This will fire the command queue:work every minute (or whatever you set it in the cron jobs tab in your cPanel)..

The above solution is not correct, I guess.. Corrections / amendments are most welcome.


Can anybody point out the mistake as to where and what I must have done? It has been more than 4 hours and I couldn't find any solution to this.

Any help is highly appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dongxin8392 2016-12-28 10:45
    关注

    You should edit the cron to be like this

    * * * * * /usr/local/bin/php /home/<username>/laravel-app/artisan schedule:run >/dev/null 2>&1
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?