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

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

问题描述

我正在寻找一些建议.

现在我有一堆通过 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 任务计划程序来运行脚本,但如何在本地运行实际的 php 脚本?据我了解,您需要像 xampp 这样的东西来运行 apache 服务器?我想我需要的是在 crontab 中等效于/usr/bin/php 的 Windows.

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:

如果您更喜欢安装 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

安排任务

转到<代码>开始->程序 ->配件 ->系统工具 ->计划任务,

  1. 右键单击计划任务窗口中的空白处,然后选择新建 -> 计划任务(也可通过文件 -> 新建 -> 计划任务访问)
  2. 为新任务命名(Bill"怎么样?他看起来像一个 Bill,是不是?Mr. 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天全站免登陆