How To Dispatch Queued Jobs In Laravel On Shared Hosting (CPanel)

Viewed 1529

Good day all. I have this persisting problem with a laravel app I created. I want to send bulk emails to subscribers. I want to queue the emails (jobs)so that they won't slow down my app. I am using a shared hosting account. Without the queue process, the mails work work fine. However, without it, they do not work. I am using database as Queue Connection and I have the "jobs" table set up in my database. I guess up till this point, everything is working perfectly well because anytime I send the mails, I can see the jobs in the database. The problem is that I can't seem to make the queue:work command on the shared hosting unlike on my system (locally).

Furthermore, I created command using php artisan make:command cronEmail, and inside App/Console/Kernel.php, I set up the schedule method as follows

protected function schedule(Schedule $schedule)
{
    $schedule->command('queue:work --tries=3')
            ->cron('* * * * * *')
            ->withoutOverlapping();
}

I then created a cron job on my cpanel as follows:

php /home/myrootfolder/mywebsitefolder/artisan queue:work >> /dev/null 2>&1

Yet, still I don't get any result. The mails are not getting sent.

My Website files are set up as follows: Inside the root folder of the cpanel, I created a new folder called "mywebsitefolder" where I put all my laravel files except for the "public folder". The contents of the public folder are placed inside the root folder's "public_html". I then edited my index.php accordingly. It's shown below:

require __DIR__.'/../mywebsitefolder/vendor/autoload.php';
$app = require_once __DIR__.'/../mywebsitefolder/bootstrap/app.php';

So, could it be that I am not pointing to my "artisan" correctly or I am getting everything completely wrong? Please, if anyone knows a better way of doing this or where I am getting it all wrong, I'll be glad. Thanks in advance.

1 Answers

You can easily from your Cpanel you will find terminal open it and run this command

nohup php artisan queue:work --daemon &

you can find the terminal in the advanced section

enter image description here

it will run your queue in the background

make sure when you run the command above to be in your project app path

Related