2

I am going to create Task Shedule in laravel 5.6 in my app. I am working with windows 7 os and my localhost is WAMP. in laravel documentation there is add Cron entries to your server as

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

but I have not any idea about how to add Cron entries with My wamp localhost. my laravel file is in the desktop name as schoolproject then how can add Cron entries with my wamp?

banda
  • 392
  • 3
  • 21
  • you can check this `http://www.web-site-scripts.com/knowledge-base/article/AA-00487/0/Setup-Cron-job-on-Windows-7-Vista-2008.html` – Lakhwinder Singh Sep 13 '18 at 12:58
  • Check the windows "Task Scheduler" program (built-in). You should be able to run a php script using it. See: https://stackoverflow.com/questions/4701861/how-do-i-run-a-php-script-using-windows-schedule-task – Mtxz Sep 13 '18 at 12:59
  • This is a windows question. You should add that tag to your question. – ryantxr Sep 13 '18 at 13:00
  • Possible duplicate of [What is the Windows version of cron?](https://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron) – ᴄʀᴏᴢᴇᴛ Sep 13 '18 at 13:00
  • put that artisan command into a .bat file then fire it using windows task scheduler. cron jobs are a linux thing :) – xanadev Sep 13 '18 at 13:04
  • I'm about to attempt the same as you, and I think this answer is on the right track: [Laravel - Task Scheduling](https://stackoverflow.com/questions/47813514/laravel-task-scheduling?rq=1#comment82631126_47813792) – Ryan Sep 14 '20 at 12:57

1 Answers1

0

For people who run a local WAMP server and their computer isn't always awake

I spent the past couple months figuring out what would work best.

First, set up your Kernel class and console commands as instructed in the Laravel docs.

In Windows, open Task Scheduler, and create a new task:

enter image description here

In the Triggers section, you can set it like this:

enter image description here

The action should be to run the PHP executable within your WAMP folder (using artisan schedule:run) as the argument:

enter image description here

But then here is an important difference from other tutorials I've seen:

For any tasks that are critical, you'll want to treat them separately.

For example, let's assume you have a task that backs up your database, and you'd like to run this every single day at noon, so your Kernel class has this command in its schedule.

But then you realize a flaw in this approach: if you were out at lunch a few days in a row and left your computer asleep, that noon task would have been missed, and now your backups would be quite stale.

So, remove that daily database backups command from the schedule in Kernel, and instead, then create a second task within Windows Task Scheduler, and set the trigger like:

enter image description here

Then in its Settings tab, you can choose "Run task as soon as possible after a scheduled start is missed":

enter image description here

Therefore, even if your computer is off or asleep at this task's scheduled time, Windows will know to run the task immediately upon waking.

Ryan
  • 17,332
  • 24
  • 141
  • 270