php CRON 命令每 5 分钟运行一次 URL 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11375260/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:22:40  来源:igfitidea点击:

CRON command to run URL address every 5 minutes

phpcron

提问by Mirgorod

I'm newbie in cron commands and I need help.

我是 cron 命令的新手,我需要帮助。

I have a script on http://example.com/check/.

我有一个脚本http://example.com/check/

Whats is command for cron to run this URL every 5 minutes?

cron 每 5 分钟运行一次这个 URL 的命令是什么?

I tried

我试过

*/5 * * * * /home/test/check.php

*/5 * * * * /home/test/check.php

But I want to run URL not relative script address. How to do it?

但我想运行 URL 而不是相对脚本地址。怎么做?

回答by Yan Berk

Use cURL:

使用卷曲:

*/5 * * * * curl http://example.com/check/

回答by DilbertDave

Based on the comments try

根据评论尝试

*/5 * * * * wget http://example.com/check

[Edit: 10 Apr 2017]

[编辑:2017 年 4 月 10 日]

This answer still seems to be getting a few hits so I thought I'd add a link to a new page I stumbled across which may help create cron commands: https://crontab.guru

这个答案似乎仍然获得了一些点击,所以我想我会添加一个指向我偶然发现的新页面的链接,这可能有助于创建 cron 命令:https: //crontab.guru

回答by Arnaud Bouchot

The other advantage of using curl is that you also can keep the HTTP way of sending parameters to your script if you need to, by using $_GET, $_POSTetc like this:

使用 curl 的另一个优点是,如果需要,您还可以使用 HTTP 方式将参数发送到脚本$_GET$_POST如下所示:

*/5 * * * * curl --request GET 'http://exemple.com/path/check.php?param1=1&param2=2'

回答by Charles Brunet

To run a url, you need a program to get that url. You can try wgetor curl. See manuals for available options.

要运行 url,您需要一个程序来获取该 url。您可以尝试wgetcurl。有关可用选项,请参阅手册。

回答by robert lenny

To run a URL simply use command below easy yess CPanel 100%

要运行一个 URL,只需使用简单的 yess CPanel 100% 下面的命令

/usr/bin/php -q /home/CpanelUsername/public_html/RootFolder/cronjob/fetch.php

I hope this help.

我希望这会有所帮助。

回答by Jorhel Reyes

I try GET 'http://example.com/?var=value'Important use 'add >/dev/null 2>&1for not send email when this activate Sorry for my English

我尝试GET 'http://example.com/?var=value'重要使用'添加>/dev/null 2>&1不发送电子邮件时激活对不起我的英语

回答by Atanas Atanasov

Nothing worked for me on my linux hosting. The only possible commands they provide are:

在我的 linux 主机上没有什么对我有用。他们提供的唯一可能的命令是:

/usr/local/bin/php absolute/path/to/cron/script

and

/usr/local/bin/ea-php56 absolute/domain_path/path/to/cron/script 

This is how I made it to work: 1. I created simple test.php file with the following content:

这就是我让它工作的方式: 1. 我创建了一个包含以下内容的简单 test.php 文件:

echo file_get_contents('http://example.com/check/');

2. I set the cronjob with the option server gived me using absolute inner path :)

2.我使用绝对内部路径给我的选项服务器设置了cronjob :)

/usr/local/bin/php absolute/path/to/public_html/test.php