使用wget和Windows Scheduler运行php脚本 [英] Running a php script using wget and Windows Scheduler

查看:75
本文介绍了使用wget和Windows Scheduler运行php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在笔记本电脑上,我已经安装了网络服务器并编写了脚本.在任何浏览器中通过http://localhost/test/search.php访问脚本都会使其正常运行:它会搜索,下载并存储某些推文.

On my laptop, I have installed a webserver and have written a script. Accessing the script through http://localhost/test/search.php in any browser makes it run properly: it searches for, downloads and stores certain tweets.

我现在想使脚本每20分钟自动运行一次,因此我在C:\Program Files\GnuWin32\bin\wget.exe中下载并安装了Windows的wget.然后,我使用以下操作(在操作"选项卡上填写)创建了Windows任务:

I now want to make the script run automagically every 20 minutes, so I downloaded and installed wget for Windows in C:\Program Files\GnuWin32\bin\wget.exe. I then created a Windows Task with the following Action (filled in on the Actions tab):

Program/script:
"C:\Program Files\GnuWin32\bin\wget.exe"

Add arguments (optional): -O - -q -t 1 http://localhost/test/search.php

按预期,每20分钟打开一个命令行以运行脚本.但是,什么也没有发生.脚本未初始化.我确信我所有的路径都是正确的.是什么原因导致脚本无法执行?命令行在几毫秒内消失,所以我看不到它的内容...

As expected, every 20 minutes a command line opens to run the script. However, nothing happens. The script isn't initialized. I am sure all my paths are correct. What could be causing that the script doesn't get executed? The command line disappears in a matter of milliseconds, so I cannot see what it says...

推荐答案

您提到了search.php的两条路径:一个是/test的路径,另一个是/ting的路径.确保在浏览器和wget中使用相同的密码.

You mention two path to search.php : one is with /test, the other is with /ting. Make sure you are using the same in the browser and wget.

如果您请求的页面不存在,则提供-q不会出错.用-v--verbose替换它以查看出了什么问题.

If you request a page that does not exist, you will get no error if you supply -q. Replace it with -v or --verbose to see what is wrong.

c:\gnuwin32\bin\wget.exe -O - --verbose -t 1 http://localhost/test/search.php
--2013-02-25 23:42:03--  http://localhost/test/search.php
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-02-25 23:42:03 ERROR 404: Not Found.

当命令行正常运行时,您可以专注于使用任务计划程序运行它.

When you get the command line working, you can focus on running it with the task scheduler.

您可以自己或任何其他帐户运行任务.使用LOCAL SERVICE,即使您已注销,也可以在不提供密码的情况下运行它.只需确保您选择的帐户具有wget所在目录的权限即可.

You can run the task as yourself, or any other accounts. Using LOCAL SERVICE allows you to run it without providing a password, even if you are logged out. Just make shure that the account you selected has permission to the directory where wget is located.

其他人提到,您必须设置计划任务的路径,否则您将获得操作码( 2)您在屏幕截图中显示了.它还将确保Windows找到wget.exe依赖项,即libeay32.dlllibssl32.dll.

Others have mentionned that you must set the path of your scheduled task, or else you will get the operationnal code (2) you showed in your screen shot. It will also make sure WIndows find wget.exe dependencies, namely libeay32.dll and libssl32.dll.

.

最后,简化一下.从命令行运行php. 上面的链接是带有简单脚本的示例.

Finally, simplify. Run php from the command line. The link above is an example of that with a simple script.

编写代码,以便可以从命令行独立调用search.php.无需在两者之间放置HTTP客户端和Web服务器.这是一堆示例脚本各种Twitter相关操作.

Write you code so that you can call search.php standalone from the command line. No need to put an HTTP client and a web server in between. Here are a bunch of sample scripts for various Twitter related operations.

这篇关于使用wget和Windows Scheduler运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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