Running Artisan Horizon on Shared Hosting - laravel

im tried to create cronjob on shared hosting with artisan horizon like this
/usr/local/bin/ea-php74 /home/example/example.com/artisan schedule:run 1>> /dev/null 2>&1
/usr/local/bin/ea-php74 /home/example/example.com/artisan horizon>> /dev/null 2>&1
but after a view hours our server goes down. any solutions for us?

Horizon is not supposed to be on a cronjob, as every time the cron triggers that line, it is a new Horizon process that has to run, so probably that's why your server is going down.
The right solution is to set up Horizon using Supervisor: https://laravel.com/docs/8.x/horizon#supervisors

Related

Laravel 7: Cron jobs for task scheduler in Cpanel not working

I'm using Namecheap Hosting. And my files are in a subdomain. I've added a task scheduler in Kernel.php file and add cron jobs in hosting. But it's not working. When I manually run schedule command it works perfectly. Can anyone please see the below code and details and tell me what am I missing?
Kerner.php file:
protected function schedule(Schedule $schedule)
{
$schedule->command('add:earnLeave')
->everyMinute()
->timezone('Asia/Dhaka');
}
Cron Command:
/usr/local/bin/php /https://subdomain.maindomain.com/php artisan schedule:run >> /dev/null 2>&1
and in my hosting the minimum run time is every five minutes */5 * * * *
and my task scheduler will run once on the last day of the month. For testing purposes, I set it to every minute. Should I have to keep this run time equal to cron jobs?
What should I do now?
Domain name no needed.
/usr/local/bin/php /home/username/public_html/laravelrootfolder/artisan schedule:run >> /dev/null 2>&1
I have solved this problem myself.
I use /usr/bin/php instead of usr/local/bin/php
And also proc_open was disabled. After enabling it, now it's working fine.

Setting up a Laravel cron job in cPanel

I have the following function:
protected function schedule(Schedule $schedule)
{
$schedule->command('email:users')->everyMinute();
}
when I run the command
artisan schedule:run
it sends an email but when I add the following command to the cpanel as a cron job it doesn't send any email. Cpanel suppose to email me a notification when the cron job is run but I haven't receive a single email.
php /home/rain/artisan schedule:run 1>> /dev/null 2>&1
Where am I doing wrong?
Also when I run the command artisan schedule:run it runs it only once. I am very curious why do I have to add ->everyMinute(); if it is not going to run every minute? If I want to send it weekly I can setup the cron job. Why do I have to write to add ->weekly(); in the function if cron job is sending it weekly?
The Laravel scheduler assumes you have a cronjob every minutes. The scheduler is only useful if you want to have multiple tasks.
Normally you have one single cronjob configured in cPanel and you can set the scheduler to everyWeek() and have another task that would be everyDay() without having to add of change the cronjobs in your cPanel.
Laravel will automagically know if the task has already been run.
https://laravel.com/docs/5.4/scheduling
This Cron will call the Laravel command scheduler every minute. When
the schedule:run command is executed, Laravel will evaluate your
scheduled tasks and runs the tasks that are due.
It worked for me:
First try your command without waiting:
/usr/local/bin/php /home/hosting-username/laravel-folder/artisan schedule:run
Then, once you checked if it worked, add this:
/usr/local/bin/php /home/hosting-username/laravel-folder/artisan schedule:run >> /dev/null 2>&1
This Works for me
/usr/local/bin/php /home/hosting-username/laravel-folder/artisan schedule:run >> /dev/null
Just Make Sure you use exact version of php to execute schedule
e.g
if your php v is 7.3 then the code will be
/usr/local/bin/ea-php73 /home/hosting-username/laravel-folder/artisan schedule:run >> /dev/null
This worked for me
/usr/local/bin/php /home2/maildoll/demo.maildoll.com/artisan queue:work --stop-when-empty >> /dev/null

How to kill the laravel queue:listen --queue=notification?

For a cron job I am using following code in laravel 5.1 and run the command in every 1 min. But even though after stopping cronjob from crontab the laravel code still executes. ?
$this->call('queue:listen', [
'--queue' => 'notification-emails','--timeout'=>'30'
]);
what could be the problem ? How can I stop this queue listen ?
You probably looking for queue:work which will stop, when no more jobs left, meanwhile queue:listen will persist.
If You want to kill existing process - You have to do it manually, because there is no command in laravel to kill all queue:listen processes.
Keep in mind, that You will not find process like artisan queue:listen, You have to look for artisan schedule:run because queue:listen, when called internally, will not create separate process.

Laravel Schedule command does not work

I used laravel 5 in my project. I wanted to create a scheduler for inserting user. In kernel.php, I put my codes and set the scheduler.
I created a command class named "InsertUser" and put it in kernel.php $commands variable.
In command line, I ran "php artisan schedule:run". But I found "No scheduled commands are ready to run.". If I used call function instead of command function (in lernel.php), it was working fine. Please help me.
The Laravel Scheduler needs a cron job that runs the php artisan schedule:run command periodically, which in turn evaluates any scheduled commands and runs them accordingly.
From your screenshot I see you're running Windows, which means you can't use the job code snippet from the Starting The Scheduler section in the documentation because there is no cron on Windows. Windows is not officially supported for the task scheduler because of that and no instructions for it can be found in the documentation.
You could however get around the problem by creating a batch file, say scheduler.bat, that has the following contents:
cd c:\lamp\www\larasoft
php artisan schedule:run 1>> NUL 2>&1
Then you can add a Windows Scheduler Task to run that file every minute.
Windows does support Laravel Scheduler but, you've to run the command on your own for multiple times. Since we can't use Windows Task Scheduler to run for every 1 min as we can do with linux crontab. If you're using windows for development environment and want to test if command is working on not you can try this
If you run the
php artisan schedule:run
command for multiple times by giving a min gap for each trial it'll work.
If you want to run directly the command you can follow this.
"path\to\php.exe" "artisan" YourCommand > "NUL" 2>&1 &
In your case
Run "where php.exe" in command prompt
Copy The php location
"paste\your\php\location" "artisan" InsertUser > "NUL" 2>&1 &

Laravel queues run forever

I have a page which supports some kind of mail notificiation. When user inserts some data, I want to send mail to another. I know, Mail::send() works perfectly, but it is slow. So I want to push this mail to queue. I use iron.io as provider. Everything works perfectly until I close console.
So is it possible to run php artisan queue:listen forever after I close console on Win and Linux?
You can run every process in the background in linux by using nohup
nohup php artisan queue:listen
This will keep the process running even if you close your terminal, nohup will force to ignore hangup signals.
nohup creates a logfile. If you want to suppress this, you can add
>/dev/null 2>&1 &
after your command

Resources