12

I am using Laravel Task Scheduling. I defined a custom command and set it to run every minute like:

$schedule->command('dailyk')->everyMinute();

Then I used the following command to run the task:

php /var/www/stockhit/artisan schedule:run 1>> /dev/null 2>&1

I used log to check that my custom command continued to run. However, it is not run every minute. Instead, it just ran once.

How can I make it run every minute, instead of just one time?

Leigh
  • 28,765
  • 10
  • 55
  • 103
alextre
  • 237
  • 1
  • 3
  • 9

2 Answers2

12

See Task Scheduling:

Here is the only Cron entry you need to add to your server:

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled tasks and runs the tasks that are due.

Laravel's task scheduler does not stay in memory, it needs to be run every minute. It will then check which tasks need to be run in that minute and run them. When you run the task scheduler using PHP it just runs once, it needs cron to run it every minute.

Eli Algranti
  • 8,707
  • 2
  • 42
  • 50
  • 2
    will it affect the performance of the server if we call it every minute? – Thanpuia Jul 11 '22 at 10:04
  • 1
    @Thanpuia the call to Laravel's task scheduler itself (i.e. the call to check whether there is something to do) should have very minimal impact on the server. Obviously depends on the server provisioned for the task, but a php application server using Laravel would be serving thousands of requests per minute, the call to the Laravel task scheduler would be one more call among them. – Eli Algranti Jul 21 '22 at 01:30
8

you need to add a cron job. On ubuntu use the command

crontab -e

to open your cron job file, then add

* * * * * php /var/www/stockhit/artisan schedule:run 1>> /dev/null 2>&1
jclyons52
  • 306
  • 3
  • 8
  • hi user3563206: i got it work by manually add the secound line into the file crontab -e open, thx – alextre May 17 '16 at 03:14