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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?