运行PHP脚本.bat文件 [英] Running a php script with a .bat file

查看:132
本文介绍了运行PHP脚本.bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在午夜每天晚上我的服务器上运行PHP脚本。在Linux系统上你可以设置cron作业,但我坚持与Windows系统。

I need to run a php script at midnight every night on my server. On a linux system I'd set up a cron job, but I'm stuck with a windows system.

我知道我必须使用Windows任务计划成立一个任务,该任务将需要运行从而将运行PHP文件.bat文件,但我坚持尝试写.BAT文件中。

I know I have to set up a task using the windows task scheduler, and that the task will need to run a .bat file which in turn will run the php file, but I'm stuck trying to write the .bat file.

我目前拥有的是:

@echo off
REM this command runs the nightly cron job
start "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php

但是,当我尝试手动运行.bat文件来测试它,我得到一个窗口警告说

But when I try to manually run the .bat file to test it, I get a windows alert saying

Windows无法找到'-f'。请确保您正确,键入名称,然后再试。

"Windows cannot find '-f'. Make sure you typed the name correctly, and then try again.

什么我错过了?

推荐答案

开始命令可以选择接受所创建的窗口作为第一个参数一个标题;在这种情况下,认为 C:\\ Program Files文件(x86)的\\ PHP \\ V5.3 \\的php.exe 是标题显示和 -f (第二个参数)是您要运行的可执行文件。

The START command optionally accepts a title for the created window as its first argument; in this case, it thinks that C:\Program Files (x86)\PHP\v5.3\php.exe is the title to display and -f (the second argument) is the executable you want to run.

您因此可以通过提供一个占位符的标题,例如解决这个问题。

You can therefore fix this by providing a placeholder title, e.g.

start "email reminder task" "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php

或者,preferably,你可以完全沟开始命令(不使用任何其独特的设施),只是直接运行PHP的:

Or, preferably, you can ditch the START command altogether (you aren't using any of its unique facilities) and just run PHP directly:

"C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php

这篇关于运行PHP脚本.bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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