18

Help needed to set up this command in my Xampp windows server

0 * * * *     cd C:/xampp/htdocs/plugins/moviefeed/ && php cron.php

Could you please point me in the right direction

thanks

asifsid88
  • 4,631
  • 20
  • 30
ashley
  • 191
  • 1
  • 1
  • 4

5 Answers5

15

On Windows OS there is no cron .... you need to use the scheduler task from Windows to create a "Cronjob". Example for using the windows scheduler

Nick
  • 3,231
  • 2
  • 28
  • 50
donald123
  • 5,638
  • 3
  • 26
  • 23
7

VladH wrote /st , I believe it should be /sc

Open a command prompt and type

schtasks /create /tn "XamppCron" /tr "L:\xampp\php\php.exe L:\xampp\htdocs\mydevsite\cron.php" /sc minute /mo 10

Once you're satisfied with the cron if you run as php-win.exe the command prompt window will not appear everytime the task is run.

oasisfleeting
  • 999
  • 12
  • 6
4

You can easily create a .bat file where you define your schedule task for windows. Regarding your needs..

set doc=C:\xampp\htdocs\project
cd "%doc%"
copy /y nul "file.php"
ECHO ^<?php echo 'This is executed via scheduler task!'; ?^> >file.php
schtasks /create /tn "Cron" /tr "C:\Program Files (x86)\Mozilla Firefox\firefox.exe http://play.local/fisierul.php" /st minute /mo 10

What I did here is:

  • I changed the path to "project" directory from "htdocs"
  • I create a file "file.php" (if it doesn't exists)
  • I write a simple echo into the "file.php" file
  • And I create a new scheduler task (similar to cron jobs in Unix) wich will open my mozilla browser and access that url every 10 minutes.

Note: to stop a scheduler task you must go in cmd and type

schtasks /delete /tn "Cron"

Good luck dude!

VladH
  • 383
  • 4
  • 16
4

I'll add nothing new but just a test case. Using the Task Scheduler GUI would be troublesome/unnecessary for a simple cron job, so this demo uses .bat files. What the demo does is just increment the number in the "counter.txt" by 1 every minute.


Created a "cron" folder in "htdocs" with these files:

  • counter.txt
  • index.php
  • schtask_add.bat
  • schtask_del.bat
  • schtask_query.bat

Contents of the files:

counter.txt

0

index.php

<?php
    $filepath = "C:/xampp/htdocs/cron/counter.txt";
    $i = file_get_contents($filepath);
    $i = (int) $i;
    $i++;
    file_put_contents($filepath, $i);

schtask_add.bat

@echo off
schtasks /Create /TN XAMPP /TR "C:/xampp/php/php-win.exe C:/xampp/htdocs/cron/index.php" /SC MINUTE /MO 1
pause

schtask_del.bat

@echo off
schtasks /Delete /TN XAMPP /F
pause

schtask_query

@echo off
schtasks /Query /TN XAMPP
pause

Tested with XAMPP 7.1.11 on Windows 10 (64-bit).


Schtasks.exe | Microsoft Docs

Schtasks - Scheduled tasks - Windows CMD - SS64.com

PHP: CLI and CGI - Manual (php.exe vs php-win.exe)

akinuri
  • 10,690
  • 10
  • 65
  • 102
-2

Cron is a Unix application for scheduled tasks, to get the same result under Windows you will need to use Task Manager.

First you create a simple task that start at 0:00, every day. Then, you go to Advanced... (or similar depending on the operating system you are on) and select the Repeat every 60 minutes.

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77