Skip to content

Instantly share code, notes, and snippets.

@Splode
Last active April 11, 2024 12:49
Show Gist options
  • Star 86 You must be signed in to star a gist
  • Fork 35 You must be signed in to fork a gist
  • Save Splode/94bfa9071625e38f7fd76ae210520d94 to your computer and use it in GitHub Desktop.
Save Splode/94bfa9071625e38f7fd76ae210520d94 to your computer and use it in GitHub Desktop.
Laravel Scheduler on Windows

Run Laravel Scheduled Tasks on Windows

The following are instructions for running scheduled tasks defined in a Laravel project on Windows. The Laravel documentation provides instructions for running scheduled tasks using cron jobs on Linux systems. However, cron jobs are not available on Windows. The built-in Windows Task Scheduler can be used to run scheduled tasks instead.

Create a Scheduled Task

  1. Open Task Scheduler
  2. Select Create Task...
  3. Give the task a name and description
  4. To run the task in the background, select Run whether the user is logged on or not and check the Hidden checkbox.

Triggers

  1. Create a new trigger.
  2. Set the trigger to run Daily and recur every 1 days.
  3. Set Repeat task every to 1 minutes. 1 minutes is not a selectable option. Simply select 5 minutes from the dropdown and then manually edit.
  4. Set for a duration of: to Indefinitely.
  5. Ensure that Enabled is checked.

Actions

  1. Create a new action.
  2. Start php by entering the php binary location, such as C:\php\php.exe
  3. Set Add arguments field to C:\{project-dir}\artisan schedule:run (replace {project-dir} with appropriate path).

Settings

  1. Check Allow task to be run on demand.
  2. Check Run task as soon as possible after a scheduled start is missed.

Wrap-up

  1. To ensure that the task is running, find the task in the Task Scheduler Library.
  2. Note the task Status. It may be Ready or Running.
  3. Note the Next Run Time and Last Run Time properties.
@gallomaf
Copy link

thank you!

@PaulKish
Copy link

I'd like to add that sometimes the scheduled task on windows might sometimes not trigger automatically, to fix this in the set the start date/time to be ahead of your current date/time

@SonoMauro
Copy link

Very helpful

@marxtinus
Copy link

Great article. Well done.

@CreateWithCoding
Copy link

Everyone, this is irrelevant now days with Laravel 8 or higher.

Every 1 minute the Laravel Scheduler checks to see if anything should be run.

Simply use the latest Laravel Scheduler or at least Laravel 8 (maybe it's Laravel 7, but for sure Laravel 8 and above)

image

@Wiliams3427
Copy link

Big help! Thank you!

@evansroy
Copy link

Thank you

@sdgonzales
Copy link

I'm trying to setup this Task on Windows 10 but I can get success. I'm using Laravel 10, Xampp and Windows 10. I followed all the steps but when the Task manager open de PHP Shell got the error "Could not open input file: C:\xampp\htdocs\rrhh\sarh\artisan. Someone can help me?

Thank you.

@CreateWithCoding
Copy link

@sdgonzales Consider using only Laravel Scheduler instead. See my post above. I'm not seeing a reason to use Windows task scheduler anymore since Laravel 8 has this covered.

@sdgonzales
Copy link

@CreateWithCoding Did You use php artisan schedule:work?

@CreateWithCoding
Copy link

@sdgonzales Exactly. That works like a champ for local dev. no need for windows task scheduler.

php artisan schedule:work

Running the Scheduler Locally

"Typically, you would not add a scheduler cron entry to your local development machine. Instead, you may use the schedule:work Artisan command. This command will run in the foreground and invoke the scheduler every minute until you terminate the command"

@sdgonzales
Copy link

@CreateWithCoding Thank you so much. What would I use for production on a server?

@CreateWithCoding
Copy link

@sdgonzales You would use: CRON Jobs on your production server.

Check the docs of your web/app hosting company.

Cloudways hosting has nice write up on how to do this:

https://www.cloudways.com/blog/laravel-cron-job-scheduling/

@mthabsheer
Copy link

I'd like to add that sometimes the scheduled task on windows might sometimes not trigger automatically, to fix this in the set the start date/time to be ahead of your current date/time

@PaulKish This really helped, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment