douna4762 2013-02-17 16:57
浏览 153
已采纳

使用wget和Windows Scheduler运行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.

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

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...

  • 写回答

3条回答 默认 最新

  • doujingke4981 2013-02-26 05:09
    关注

    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.

    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.

    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.

    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.

    Set a working directory for your scheduled task.

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

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog