Laravel 7 run queue:listen from route on shared hosting

1.1k views Asked by At

I am wondering how to run php artisan queue:listen database manually to execute a job on a shared hosting. I am trying it from route file web.php :

Route::get('/job', function () {
    Artisan::call('queue:listen');
    return 'Job Started....';
});

Another approach I tried with cron job in cPanel:

/usr/local/bin/php/home2/courage/project_folder/artisan queue:listen database --daemon  

But both the approach is not working. I am able to run the job from local. How can I achieve this??

1

There are 1 answers

3
ssi-anik On BEST ANSWER

Laravel queue:[listen|work] is a long-running background task. Once it starts, unless you send a quit/terminate signal, it runs for the lifetime. On the other hand, all the HTTP calls have timeouts. So, if you call an HTTP endpoint, if your application (can be of any technology stack), will timeout after a certain period of time (generally 30s).

So, in theory, yes. In your HTTP endpoint, you can run the command using the Artisan facade, but it'll stop working after it hits the t/o.

Secondly, your cron. Crons are supposed to work in a periodic manner. Suppose you want to transfer your logs from your server to another server after 5 mins, in those cases, you can run crons. Crons are like schedule jobs. So practically, crons don't have any effect in your case as well.

Finally, in shared hosting, you can only serve HTTP req-res only, unless the provider provides you the ssh access. As others said in the comments, you can't use the full functionality of Laravel in shared hosting. You need to move from shared hosting to any VPS.