通过任务管理器在本地运行php脚本 [英] running php scripts locally though task manager

查看:216
本文介绍了通过任务管理器在本地运行php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些建议.

Rignt现在,我已经通过cron计划了一堆php脚本.它们在我的本地计算机上运行,​​执行诸如从mysql数据库中提取内容并发送自动电子邮件之类的操作.要运行它们,我在crontab中只有这样的内容:0 7 * * 1 /usr/bin/php /phpscripts/script.php

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

我需要将所有这些脚本迁移到Windows计算机.我打算使用Windows Task Scheduler运行脚本,但是如何在本地运行实际的php脚本?据我了解,您需要xampp之类的东西来运行apache服务器?我猜我需要的是Windows上crontab中的/usr/bin/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.

推荐答案

安装PHP

您不必安装xammp,您可以单独安装PHP,请参阅Windows PHP安装指南:

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

  • Windows Installer (PHP 5.1.0 and earlier)
  • Windows Installer (PHP 5.2 and later)
  • Manual Installation Steps

如果您喜欢安装XAMP,则可以在使用-f标志定位php.exe之后运行PHP脚本:

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

运行PHP文件

安装PHP后,请检查 Microsoft Windows手册上的命令行PHP 有关如何运行脚本的信息.在页面上有关于如何使php文件可执行的解释,因此您可以按以下方式运行它:

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

确保您使用的是管理帐户来运行命令.否则,您可能会遇到权限问题.在在命令行上使用PHP的介绍

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

安排任务

转到Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks

  1. 右键单击计划任务"窗口中的空白处,然后选择新建"->计划任务"(也可以通过文件"->新建"->计划任务"访问)
  2. 命名新任务(比尔"怎么样?他看起来像比尔,不是吗?"B.Evolution先生,II"听起来很富裕.)
  3. 双击新任务以打开属性窗口(或文件"->属性")
  4. 在任务"选项卡下,输入用于测试上述脚本的相同命令.例如,我输入:
  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"

  • 转到计划"选项卡,然后输入任务运行的时间和频率.该计划默认每天运行一次,对于基本用法来说应该可以,但是可以根据需要随时进行调整.
  • 除非您是王牌并且知道自己在做什么,否则其余字段可以保持不变.
  • 单击确定",我们就完成了!
  • C:\PHP\php.exe "C:\Inetpub\wwwroot\blogs\cron\cron_exec.php"

  • 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.
  • The rest of the fields can be left as-is, unless you're an ace and know what you're doing.
  • Click OK and we're done!
  • 有关更多信息,请参见设置窗口计划任务.

    for more info have a look at setting up a window scheduled task.

    这篇关于通过任务管理器在本地运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆