How to get "cron" support in Laravel 4? - php

Does self-hosted (non-Forge) Laravel have a cron system? Or has this been supplanted by worker queues?
That is, in many PHP frameworks, there's a single cron file to run -- often named cron.php. You're usually instructed to configure this script to run every 15 minutes (or some similar time) via a unix cron job.
1,15,30,45 * * * * /path/to/php /path/to/cron.php
Does Laravel have a similar system? Googling about I've seen some mentions that Forge has a solution for this, and that older version of Laravel might have had a system, but I haven't been able to find a clear answer W/R/T Laravel 4.

You can schedule artisan commands and make your own commands like so:
php artisan command:make cronCommand
Which will result in a cronCommand.php file in your app/commands directory
Then you make artisan aware of the command
Add Artisan::add(new cronCommand); to app/start/artisan.php
composer dump-autoload
Now you can see your new command via php artisan list
and schedule it via 1,15,30,45 * * * * artisan cronCommand
Reference
Laravel Commands - Documentation
Taylor Otwell - Building Artisan Commands
Dispatcher - Artisan Command Scheduler

Related

Run Laravel queue on production

Could you please share your best solution for run Laravel queue on production server?
For now I see next solution:
First start queue:
php artisan queue:work >> /var/log/queue.log &
Add to crontab:
10 2 * * * php artisan queue:restart
11 2 * * * php artisan queue:work >> /var/log/queue.log &
In case of project update on server:
php artisan down
php artisan queue:restart
#do update
php artisan queue:work >> /var/log/queue.log &
php artisan up
But I'm worrying about high load case. What if some job will be stucked?
Maybe you have better solution?
You can set up the laravel supervisor to run the queues automatically instead of using the cronjobs
Please find below the article for more details to run the queue automatically on the server without cronjob
Integration of Laravel Supervisor to process Queues

Laravel - What is the usage of schedule time setting when lastly it uses OS cron job?

Laravel docs:
cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
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.
I run these codes below in app\Console\Kernel.php:
$schedule->job(new \App\Jobs\done)->everyMinute();
$schedule->command('done:done')->everyMinute();
but none of them worked! so I run the command php artisan schedule:run but it runs only once and each time I want to make it trigger the job/command I should run that command so I tried to use the command above in Laravel docs. However again it didn't work every minute. So I tried to create a task in Task Scheduler and run it every 5 minutes(because it didn't have less than 5) now it's working but the usage of ->everyMinute() is redundant because the schedule of Laravel only runs but the main job that is done is by Windows Task Scheduler. So how can I fix it in order not to use cron job nor windows task scheduler?
Thanks
Just so you can close the question.
As I said in the comments / chat
You should be able to set every minutes on Windows Task Scheduler:
http://somoit.net/windows/scheduled-task-every-minute
You can also use php artisan done:done in your Windows Task Schedule and not use the Laravel Kernel at all.
For the fact that everyMinute() is ignored when you run the job manually is because Laravel know that a cron can't be executed more than once a minute. So it doesn't keep a trace for a job set to everyMinute(). This mean, every time you run the command php artisan schedule:run it will run the job.
And has #kyslik mentioned in the chat : The scheduler is well covered in the official documentation: https://laravel.com/docs/5.7/scheduling#introduction

Laravel not running Cronjob on Ubuntu NGINX

I have setup the follow Laravel Cronjob command:
protected function schedule(Schedule $schedule)
{
$schedule->command('DataDownloader:downloaddata')->dailyAt('19:34');
}
This saves some data from an API into a mySQL database. The command is listed under php artisan and I am able to run it using php artisan DataDownloader:downloaddata.
I have added the Cron entry to my crontab as per Laravel documentation:
* * * * * php /var/www/html/myprojectname/artisan schedule:run >> /dev/null 2>&1
When I run php artisan schedule:run it tells me 'No scheduled commands are ready to run'. I don't really know if this suggests if my Cronjob does not work at all or it is just broken.
Am I missing something or did I do something wrong that prevents the Cron from running?
My server is running Ubuntu with NGINX.
schedule:run command fires other commands that are ready to run at the time of its execution. So it means that in that exact time you ran it, no command was to be started.
However, you have defined cron that runs schedule:run every minute, thus when 19:34 comes, your command will be executed.

Run artisan command in Kernel.php

i have installed a Laravel package for dumping my database.
The plugin runs find, but i want to run it every day as a cronjob.
Here is the inserted command in Kernel.php:
$schedule->command('db:backup')->dailyAt('01:50');
Unfortunately it hasn't done anything.
Is it possible to run an artisan command direct in the Kernel.php without a Command class ?
Have you made sure to add the task to your system crontab? Typically located at /etc/crontab
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
From https://laravel.com/docs/5.3/scheduling
PHP has no way of executing itself, so you need to set up a system task to call artisan every second, so laravel can evaluate the cron expressions and run them as needed.

Setting up task scheduler in Laravel 4.2

I am trying to develop an app in Laravel 4.2 framework. For this purpose, I tried to set up task scheduler.
I have created commands for scheduling and it works well.
In Laravel documentation, they mentioned that we need to add Cron entry to server:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1.
I don't know where to add this command. Can anyone help? I am using xampp in windows os
In Windows this is called Task Scheduler.
Just make sure you use full paths to php.exe and artisan as well.

Categories