Setting Up A Cronjob In Windows Xampp

后端 未结 5 1128
终归单人心
终归单人心 2020-12-04 20:35

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

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

C

相关标签:
5条回答
  • 2020-12-04 20:57

    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

    0 讨论(0)
  • 2020-12-04 20:57

    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.

    0 讨论(0)
  • 2020-12-04 21:02

    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.

    0 讨论(0)
  • 2020-12-04 21:04

    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!

    0 讨论(0)
  • 2020-12-04 21:04

    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)

    0 讨论(0)
提交回复
热议问题