Laravel Queue queue:work running in background in Shared hosting(CPanel) - laravel

In my project, I've made a simple newsletter system where I want to send an email to all subscribers. But the problem I faced in production (Cpanel hosting) I have to run laravel queue:work command in terminal. Can anyone tell me how to handle queue:work in background in CPanel hosting...
can anyone tell me how to handle this problem?
For sending the mail I'm using the cpanel mail smtp not using any other third party like mailchimp or mailgun etc...

**find crob job tab into your cpanel then set the cron job **
like
daily
after 5minutes or whatever you want
make a job to handle the user news letters like
php artisan make:job UserNewsLetters
and then make a email
php artisan make:mail NewsLetterEmail
make a view into mail/newsletter
access the mailabel into your job set cron job path to your project folder like this /usr/local/bin/php /home/hosting_user/public_html/artisan queue:work or you can utilize laravel console commands https://laravel.com/docs/8.x/scheduling
please check this image and set cron job not run commandline
add this command into your cron task with full php path
php /path/to/laravel/artisan queue:work --stop-when-empty
to check php path run this in commandline
which php
cron task have these options to run your job
1-once per minute (mean job only run once in one minute so once per minute mean it will run 60 times in One Hour)
2-Every day mean once in 24hr
3- weekly job run once in a week
you can also make console commands for schedule your task and laravel have clear documentation Task Scheduling

Related

Laravel Cron Job not running over ubuntu server

I have a laravel application setup over Ubuntu server using Nginx. Here I have the cron jobs. I was facing an issue, that the server was not automatically picking up changes on Jobs Files. So I googled the things, and found a command from this article which I ran;
php artisan queue:restart
Since I have run this command, now no job is running even. I am also trying with simple HeartbeatJob to log info but it is also not working. When I do php artisan schedule:run,
no error in particular just screen output as:
[2021-09-11T08:41:32+00:00] Running scheduled command: App\Jobs\Heartbeat
But nothing happens. Any idea what this queue command has done wrong and how I make my jobs working again?
Your cron job will need the absolute path to artisan, so should look something like :
php /home/user/site.com/artisan queue:restart
You may also need to specify the queue with :
php /home/user/site.com/artisan queue:restart --queue=nameofqueue

laravel vapor schedule job not running as scheduled

I have setup a laravel vapor as per documentation. Everything is working fine except scheduler.
I have set few artisan commands at certain intervals. But commands are not running as per schedule. If i run command manually it works. Seems like artisan schedule:run is not running and hence commands are not fired on defined time.
I checked lamda cli logs, no errors found. What do i check?
I fixed the issue adding below line in vapor.yml
scheduler: true
This was happening to me but in my case it was solved by composer dump-autoload.

Laravel 5.3 queue worker, stop after some time through Jenkins

In Laravel 5.3.
I'm running through jenkin a command of laravel:
php artisan queue:work
But I need to stop it. Ideally I would like to stop the worker after the queue jobs gets empty, but it's not possible on Laravel 5.3. So another option would be to stop the command after sometime, let's say 1 minute.
How can I stop a process running through jenkins after some time? or stop a php artisan command.
With php artisan queue:restart I can stop all the jobs so I tried:
php artisan queue:work
sleep 60; php artisan queue:restart
But that 2nd line will never get reached because the workers is still running.
Any tip?
you can use some solution form solve it
1.
You save server resources by avoiding booting up the whole app on
every job.
You have to manually restart the worker to reflect any
code change you made in your application.
You can also run:
php artisan queue:work --once
2- This will start an instance of the application, process a single job, and then kill the script.
php artisan queue:listen
The queue:listen command simply runs the queue:work --once command inside an infinite loop, this will cause the following:
An instance of the app is booted up on every loop.
The assigned worker will pick a single job and execute it.
The worker process will be killed.
Using queue:listen ensures that a new instance of the app is created for every job, that means you don't have to manually restart the worker in case you made changes to your code, but also means more server resources will be consumed.

php artisan queue:work freeze in terminal

I use the queue in my Laravel 5.4 project to send emails in background.
I have created the table for jobs, created the class for the job, and put QUEUE_DRIVER=database in my .env file. When I dispatch my Job, I can see my task in the jobs table. So far so good.
However, when I then execute the command
php artisan queue:work on the webserver - it's freezing and not have any results.
What could be the problem?
This probably is because this is a service that uses the current thread in Ubuntu (from your tag). If you add a &, the process will run in a forked thread.
php artisan queue:work &
Or after a quick google, you can have a look at
nohup php artisan queue:work --daemon &

Cronjob setup for laravel 4.2 in cpanel

I am using laravel 4.2. I have created command file for cron job and added it into artisan file. I tested it in command. Everything is working fine in localhost. In Cpanel server I gave command path like,
php /home/fridayburr/public_html/version1/artisan active:user 1>> /dev/null 2>&1
But cron job is not working.
This is how I did in my shared Hosting using CPANEL
Here CRON Task is set on UNIX, to run every minute.
Add the schedule call with appropriate time schedule.
laravel Schedule documentation

Resources