Help needed to set up this command in my Xampp windows server
0 * * * * cd C:/xampp/htdocs/plugins/moviefeed/ && php cron.php
C
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
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.
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.
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:
Note: to stop a scheduler task you must go in cmd and type
schtasks /delete /tn "Cron"
Good luck dude!
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:
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)