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

后端 未结 12 1330
梦谈多话
梦谈多话 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 03:09

    If the answer given by Pekka does not work (C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php), make sure that you have the correct PHP extensions enabled as well as the correct php.ini file being used for the PHP version you are using.

    I ran into this issue recently and resolved it. I was using PHP v5.4 to run my script.php that was nested within the top level PHP folder (v5.3). When I ran the script.php, from within the v5.4 folder, it was using the v5.3 php.ini file with different extensions, which caused the script.php to fail.

    To fix this, here is what I did within the Task Scheduler : Actions tab

    Program Script:

    "C:\Program Files (x86)\PHP\v5.4\php.exe"

    Add Arguements:

    -c "C:\Program Files (x86)\PHP\v5.4\php.ini" -f "C:\Xampp\htdocs\script.php"

    Using the -c option, you can specify which php.ini file should be used (stackflow answer).

    I verified which php was in use by following this stackflow answer.

    In command line, type php -m to check which extensions are enabled. Then, use php --ini to check which .ini file(s) is/are being read by PHP.

    You may not be using the correct ini file for the PHP version you are using if you have multiple versions installed.

提交回复
热议问题