Linux 使用 WGET 运行 cronjob PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5766772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using WGET to run a cronjob PHP
提问by Abdullah Alsharif
I tried to do a cron and run a url every 5 mintues.
我试着做一个 cron 并每 5 分钟运行一个 url。
I tried to use WGET however I dont want to download the files on the server, all I want is just to run it.
我尝试使用 WGET 但是我不想下载服务器上的文件,我只想运行它。
This is what I used (crontab):
这是我使用的(crontab):
*/5 * * * * wget http://www.example.com/cronit.php
Is there any other command to use other than wget to just run the url and not downlaod it?
除了 wget 之外,还有其他命令可以用来运行 url 而不是下载它吗?
采纳答案by James C
You could tell wget to not download the contents in a couple of different ways:
您可以通过几种不同的方式告诉 wget 不要下载内容:
wget --spider http://www.example.com/cronit.php
which will just perform a HEAD request but probably do what you want
它只会执行 HEAD 请求,但可能会执行您想要的操作
wget -O /dev/null http://www.example.com/cronit.php
which will save the output to /dev/null (a black hole)
这会将输出保存到 /dev/null (一个黑洞)
You might want to look at wget's -q switch too which prevents it from creating output
您可能还想查看 wget 的 -q 开关,这会阻止它创建输出
I think that the best option would probably be:
我认为最好的选择可能是:
wget -q --spider http://www.example.com/cronit.php
that's unless you have some special logic checking the HTTP method used to request the page
除非你有一些特殊的逻辑来检查用于请求页面的 HTTP 方法
回答by Emil Vikstr?m
wget -O- http://www.example.com/cronit.php >> /dev/null
This means send the file to stdout, and send stdout to /dev/null
这意味着将文件发送到标准输出,并将标准输出发送到 /dev/null
回答by Mosiur
I tried following format, working fine
我尝试了以下格式,工作正常
*/5 * * * * wget --quiet -O /dev/null http://localhost/cron.php
回答by angelrove
If you want get output only when php fail:
如果您只想在 php 失败时获得输出:
php -r 'echo file_get_contents(http://www.example.com/cronit.php);'
This way you receive an email from cronjob only when the script fails and not whenever the php is called.
这样您只会在脚本失败时收到来自 cronjob 的电子邮件,而不会在调用 php 时收到电子邮件。