How do I run a PHP script using windows schedule task?

后端 未结 12 1293
梦谈多话
梦谈多话 2020-11-27 02:46

I have installed localhost/server in my machine and I need to run a php script using windows schedule task. how do I add path in \"Actions\" tab in schedule task / cofigure

相关标签:
12条回答
  • 2020-11-27 02:58

    you can directly call your local host url by using

    explorer "http://localhost/yourFile.php"
    
    0 讨论(0)
  • 2020-11-27 03:02

    You can use PHP Command Line to execute it rather then trying to load it through the browser.

    Under the actions tab, create a new action and:

    • Program/Script: Point to your PHP.exe file
    • Add Arguments: -f /path/to/php/file.php

    Optionally you can make it start in the script's directory as well.

    0 讨论(0)
  • 2020-11-27 03:02

    create Schedule task Scheduler->Actions->Edit Action

    if you have php file

    Program/script: powershell 
    Add arguments: curl http://localhost/demo/cron.php
    

    if you have MVC/CMS URL

    Program/script: powershell
    Add arguments: curl http://localhost/demo/controller/method
    
    0 讨论(0)
  • 2020-11-27 03:02

    Here's how I did it.

    In the Run box: c:\location_of_my_php_installation\php.exe -f c:\location_of_my_php_file\php_file.php

    In the Start in box: c:\location_of_my_php_installation\php.exe

    0 讨论(0)
  • 2020-11-27 03:02

    To create a scheduler in Windows, you need to:

    1. Create .bat file on your server or system;
    2. Type the following command in your.bat file:
      “F:\xampp\php\php.exe” -f “F:/xampp/htdocs/sitefolder/test.php”;
    3. Set the scheduler time and file in your task scheduler in Windows.
    0 讨论(0)
  • 2020-11-27 03:04

    Locate the php.exe executable on your system and pass it the name of the script file using the -f parameter.

    Example:

    C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php
    

    Reference:

    • Introduction to using PHP on the command line
    • PHP command line options
    0 讨论(0)
提交回复
热议问题