简体   繁体   中英

Laravel 5.3 Queues not working in shared hosting

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.

您应该将cron编辑成这样

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM