简体   繁体   English

使用 WGET 运行 cronjob PHP

[英]Using WGET to run a cronjob PHP

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 而不是下载它吗?

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 方法

wget -O- http://www.example.com/cronit.php >> /dev/null

这意味着将文件发送到标准输出,并将标准输出发送到 /dev/null

我尝试了以下格式,工作正常

*/5 * * * * wget --quiet -O /dev/null http://localhost/cron.php

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 时收到电子邮件。

您可以使用此代码使用 cpanel 使用 cron 作业命中脚本:

wget https://www.example.co.uk/unique-code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM