Search code examples
phplaraveltasklaravel-artisancron-task

Laravel Task Scheduler on Windows Server


I am trying to use the Laravel Task scheduler on a windows server but after various research, I can't figure out how to do this.

Obviously I can do this on linux but as I can understand triggering artisan from the windows task scheduler , is not enough.

Could you please help me out on this?


Solution

  • here are the steps you should follow in order to perform the desired task

    • 1 create a .bat file with the next content, I recommend to save this bat file inside a directory into your application folder.
       cls 
       cd C:\xampp\htdocs\ProjectName 
       php artisan schedule:run dir
    
    • 2 you must change C:\xampp\htdocs\ProjectName to the location of
      yout application and then save it.

    • 3 press Windows + R, write Taskschd.msc and press enter

    • 4 left click on Task Scheduler (Local) > click on 'create task'

    • 5 In the 'general' tab write a Name for the task into the Name
      field

    • 6 Check the radio button 'Run whether user is logged on or not'

    • 7 In the tab 'Actions' click on 'New', in the field 'Action' select
      'Start a program'

    • 8 Click on 'browse' and search and select the .bat file you just
      created and the press on 'OK'

    • 9 In the tab 'Triggers' press on 'New'

    • 10 In the Field 'Begin the task' select 'On a schedule'

    • 11 In settings check radio button 'Daily' > in Start set the hour
      to 1:00:00 a.m. > in Recur every set 1 days

    • 12 Into advanced settings check 'Repeat task every' and set [ 5
      minutes +] for a duration of [Indefinitely +]

    • 13 In advanced settings the checkbox 'Enabled' must be checked

    • 14 press OK

    • 15 in the tab 'Settings' you must have the next configurations [/] Allow task to be run on demand [/] Run task as soon as possible after a scheduled start is missed [/] If the task fails, restart every 1 minute [/] Stop the task if it turns longer than 3 days [/] if the running task doesn´t end when requested force it to stop if the task is already running, then the following rule applies [Queue a new instance +]

    • 16 press the OK button, write the user password , and then you
      could start the task if you need

    I hope this to be useful for you.