Linux 使用 CRON 作业访问 url?

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

Using CRON jobs to visit url?

linuxweb-applicationswebcpanelcron-task

提问by SaidbakR

I have a web application that has to perform a repeated tasks, Sending messages and alerts, I, already, use a script page do those tasks when it loaded in the browser i.e http://example.com/tasks.phpand I included it by the mean of iframe in every page of my web application.

我有一个必须执行重复任务的 Web 应用程序,发送消息和警报,我已经使用脚本页面在浏览器中加载时执行这些任务,即http://example.com/tasks.php并且我包括它通过 iframe 在我的 Web 应用程序的每个页面中实现。

Now I want to change this to use CRON jobs because the first approach may leads to jam performance, So How could I make a CRON job that visits http://example.com/tasks.php. However, I don't want this CRON job creating output files such as day.*!

现在我想将其更改为使用 CRON 作业,因为第一种方法可能会导致卡纸性能,那么我如何制作访问http://example.com/tasks.php的 CRON 作业。但是,我不希望此 CRON 作业创建诸如 day.* 之类的输出文件!

I host the application on shared hosting service that permits CRON jobs via cPanel.

我将应用程序托管在允许通过 cPanel 进行 CRON 作业的共享托管服务上。

采纳答案by Mitch Dempsey

* * * * * wget -O - http://yoursite.com/tasks.php >/dev/null 2>&1

That should work for you. Just have a wgetscript that loads the page.

那应该对你有用。只需有一个wget加载页面的脚本。

Using -O -means that the output of the web request will be sent to STDOUT (standard output)

using-O -表示将 web 请求的输出发送到 STDOUT(标准输出)

by adding >/dev/nullwe instruct standard output to be redirect to a black hole. by adding 2>&1we instruct STDERR (errors) to also be sent to STDOUT, and thus all output will be sent to a blackhole. (so it will load the website, but never write a file anywhere)

通过添加>/dev/null我们指示标准输出重定向到一个黑洞。通过添加2>&1我们指示 STDERR(错误)也被发送到 STDOUT,因此所有输出将被发送到黑洞。(所以它会加载网站,但永远不会在任何地方写入文件)

回答by Diego Torres Milano

You don't need the redirection, use only

你不需要重定向,只使用

* * * * * wget -qO /dev/null http://yoursite.com/tasks.php

回答by mrraka

You can also use the local commandline php-cli:

您还可以使用本地命令行 php-cli:

* * * * * php /local/root/path/to/tasks.php > /dev/null

It is faster and decrease load for your webserver.

它更快并减少您的网络服务器的负载。

回答by Abbas Arif

i use this commands

我使用这个命令

wget -q -O /dev/null "http://example.com/some/cron/job.php" > /dev/null 2>&1

Cron task:

定时任务:

* * * * * wget -q -O /dev/null "http://example.com/some/cron/job.php" > /dev/null 2>&1

回答by Jerzy Dro?d?

You can use curlas is in this thread

您可以curl在此线程中按原样使用

For the lazy:

对于懒人:

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

This will be executed every 5 minutes.

这将每 5 分钟执行一次。

回答by VPS-Managed.com

you can use this for url with parameters:

您可以将其用于带参数的 url:

lynx -dump "http://vps-managed.com/tasks.php?code=23456"

lynx is available on all systems by default.

默认情况下,lynx 在所有系统上都可用。

回答by Abdul Alim

You can use this command:

你可以使用这个命令:

links https://www.honeymovies.com

回答by Walk

U can try this :-

你可以试试这个:-

    wget -q -O - http://www.example.com/ >/dev/null 2>&1

回答by Vladimir Kornea

* * * * * wget --quiet https://example.com/file --output-document=/dev/null

* * * * * wget --quiet https://example.com/file --output-document=/dev/null

I find --quietclearer than -q, and --output-document=/dev/nullclearer than -O - > /dev/null

我发现--quiet-q,而且--output-document=/dev/null-O - > /dev/null