Laravel queue:work runs forever - laravel

I have a weird issue with Laravel queue:work.
In my crontab I setup a job like described in Laravel Docs
* * * * * nginx php /path/to/site/artisan schedule:run >> /dev/null 2>&1
And in my app/Console/Kernel.php I setup this:
$schedule->command('queue:work')->cron('* * * * *');
On my production server php artisan queue:work runs for a few seconds and gets "killed". Thats what I expect.
On my dev box php artisan queue:work runs forever. So activating the cron job spawns php processes until the whole memory is filled up.
Both boxes are CentOS 7.4, production runs PHP 7.1 and dev runs PHP 7.2
As said in the comment below, I don't think that the cron command is the issue.
Running form ssh:
php artisan queue:work
on dev runs forever on production a few seconds.

You can try to run it once, this runs a single job and then quits the process.
php artisan queue:work --once=1
Or in your PHP code using the Artisan facade:
Artisan::call('queue:work', [
'--once' => 1, // Do NOT run it as a daemon (not a continuous function)
'--tries' => 1,
'--queue' => 'yourqueue',
'--timeout' => 0
]);

Related

How to automatically call laravel cron jobs while website is running

I am working with task scheduling in laravel. It's working well by using artisan command in cmd. But what's the problem with automatically calling the task on server. It's not running every minute.
https://laravel.com/docs/8.x/scheduling#running-the-scheduler
You will need to setup a cron job on your server that calls your scheduler
If you using Laravel Scheduler, you have to access in your server via ssh.
ssh user#<IP-address>
edit crontab file to call every minute php artisan schedule:run artisan command.
So:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
If it not start,try to restart the web server. If you are using nginx, for ex.: sudo systemctl restart nginx

Laravel Job Not being attempted

Laravel is not being attempted (attempts = 0). I have created jobs table and dispatched a job.
The job is now currently being listed in the jobs table but with attempts = 0
I have updated QUEUE_CONNECTION=database and run php artisan config:cache. I have also hit queue:restart but still same result.
Additionally, I have tried with php artisan queue:work --force (without force as well) and php artisan queue:listen as well but still not being attempted.
You have dispatched the job to the property queue. To process this queue run:
php artisan queue:work --queue=property

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 &

Laravel php artisan serve logs stored and start artisan serve automatically

id like to know :
Where Laravel php artisan serve command logs stored ?
How to automatically start php artisan serve when sever (Apache) starts ?
Laravel logs are stored at storage/logs
You don't need artisan serve, if you have Apache handling your HTTP traffic.
To the first question
Where Laravel php artisan serve command logs stored ?
Laravel server logs are stored in storage/logs folder ,which contains files for the server logs
To the second question
How to automatically start php artisan serve when sever (Apache) starts ?
If you need to automatically ,A very simple way to do this would be to use use laravel scheduling Artisan Commands using cron
Ensure cron is installed yum install vixie-cron (assuming you use centos). Start it with service crond start
Add laravel Schedule object vi /etc/crontab and add * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 ,to the cron schedule file .
Go to app/Console/Kernel.php file and add $schedule->command('foo')->withoutOverlapping(); where foo is the artisan command you would like to run in this case serve , so it should be $schedule->command('serve')->withoutOverlapping();
Restart cron deamon with service crond restart.
See this related question https://stackoverflow.com/a/34096590/1226748
I would definitely recommend NOT using artisan's server in production like EVER, it's for testing only. -- You would be WAY better off to use nginx as a reverse proxy and you can set whatever port you want that way, and have your angular app still connect to it.

Resources