dow56114 2012-08-28 11:21
浏览 71
已采纳

通过任务管理器在本地运行PHP脚本

I'm looking for some advice.

Rignt now i've got a bunch of php scripts that i've scheduled through cron. They run on my local machine doing stuff like pulling stuff out of a mysql db and sending automated emails. To run them I just have something like this in crontab: 0 7 * * 1 /usr/bin/php /phpscripts/script.php

I need to migrate all of those scripts to a Windows machine. I'm planning to use the Windows Task Scheduler to run the scripts, but how can I run the actual php scripts locally? From what I understand you need something like xampp to run the apache server? I guess what I need is a Windows equivalent of /usr/bin/php in crontab.

  • 写回答

2条回答 默认 最新

  • doublel83422 2012-08-28 11:38
    关注

    Installing PHP

    You don't have to install xammp, you can install PHP alone, have a look ate the windows PHP installation guide:

    If you prefer installing XAMP, you can run PHP script after locating the php.exe with the -f flag:

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

    Running the PHP file

    After you have PHP installed, check Command Line PHP on Microsoft Windows manual for information on how to run the script. On the page there is explanation of how to make the php file executable, so you could run it as:

    "C:\PHP Scripts\script" -arg1 -arg2 -arg3
    

    Make sure you are using an administrative account to run the command. Otherwise you might have permissions problems. more info at the Introduction to using PHP on the command line

    Scheduling the task

    Go to Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks,

    1. Right-click on an empty spot in the Scheduled Task window and select New -> Scheduled Task (Also accessible via File -> New -> Scheduled Task)
    2. Name the new task (How about "Bill"? He looks like a Bill, doesn't he? "Mr. B. Evolution, II" It sounds so regal.)
    3. Double-click the new task to open the properties window (or File -> Properties)
    4. Under the Task tab, enter the same command that you used to test the script above. For instance, I would enter:

      C:\PHP\php.exe "C:\Inetpub\wwwroot\blogs\cron\cron_exec.php"

    5. Go to the Schedule tab and enter when and how often the task should run. The schedule defaults to run once daily and should be fine for basic usage, but feel free to tweak as needed.
    6. The rest of the fields can be left as-is, unless you're an ace and know what you're doing.
    7. Click OK and we're done!
    for more info have a look at setting up a window scheduled task.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 想写一个文件管理器,加载全部子文件夹后,要一级一级返回
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
  • ¥15 哪位能做百度地图导航触点播报?
  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?