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
Using CRON jobs to visit url?
提问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 wget
script 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/null
we instruct standard output to be redirect to a black hole.
by adding 2>&1
we 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?
回答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 --quiet
clearer than -q
, and --output-document=/dev/null
clearer than -O - > /dev/null
我发现--quiet
比-q
,而且--output-document=/dev/null
比-O - > /dev/null