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条)

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名