在backgroud中每分钟点击一次URL

时间:2021-03-31 01:08:39

I want to hit a URL of my application through cron job. I have done the following things:

我想通过cron作业来访问我的应用程序的URL。我做过以下事情:

1) Opened the terminal

1)打开终端

2) Did crontab -e which gives me an editor that allows me to put statements

2) Did crontab -e,它给了我一个编辑器,允许我放置语句

3) Pasted the URL that needs to be hit after specified interval of time:

3)粘贴指定时间间隔后需要点击的URL:

curl -s  http://www.example.com/controller/function_to_execute

This cron job will run every minute

这项工作每分钟都要进行

4) Saved the cron and again on terminal did crontab -l, and I could see my cron

4)crontab -l在终端上保存了cron,我可以看到我的cron。

This scheduler isn't working, don't know why. I tried curl on the terminal directly expecting some output, but after 5 minutes it gives me the result

这个调度器坏了,不知道为什么。我在终端上尝试了curl,希望得到一些输出,但是5分钟后,结果出来了

curl: (7) couldn't connect to host

If I hit my URL on browser directly then my job gets successfully executed!

如果我直接在浏览器上点击我的URL,那么我的任务将被成功执行!

Have I made some mistake while making entry in the cron?

我在进入cron时犯了什么错误吗?

2 个解决方案

#1


1  

First you need to create the php script and run the script using cronjob
1)Open terminal and type crontab -e
2)Edit the file and write the following code to run the php script in background

首先,需要创建php脚本,并使用cronjob 1)打开终端运行脚本,输入crontab - e2)编辑文件,编写以下代码在后台运行php脚本

*/1 * * * * php /yourpath/yourphpfile.php

3) Create yourphpfile.php and write the code to hit the url
you have to execute and test the yourphpfile.php before doing cronjob

3)创建yourphpfile。php并编写代码以命中要执行和测试yourphpfile的url。php之前做的计划

#2


1  

Whoops!..tried to just curl www.google.com and gave the following output in form of HTML tags "302 Document has moved", Also I am not able to ping the application itself from the terminal but it is accessible publicly

哎呀! . .尝试只使用curl www.google.com,并以HTML标记“302文档已移动”的形式给出如下输出,我也无法从终端对应用程序本身进行ping,但它是可以公开访问的

So cron job getting executed is out of question :P

所以cron作业被执行是毫无疑问的P

#1


1  

First you need to create the php script and run the script using cronjob
1)Open terminal and type crontab -e
2)Edit the file and write the following code to run the php script in background

首先,需要创建php脚本,并使用cronjob 1)打开终端运行脚本,输入crontab - e2)编辑文件,编写以下代码在后台运行php脚本

*/1 * * * * php /yourpath/yourphpfile.php

3) Create yourphpfile.php and write the code to hit the url
you have to execute and test the yourphpfile.php before doing cronjob

3)创建yourphpfile。php并编写代码以命中要执行和测试yourphpfile的url。php之前做的计划

#2


1  

Whoops!..tried to just curl www.google.com and gave the following output in form of HTML tags "302 Document has moved", Also I am not able to ping the application itself from the terminal but it is accessible publicly

哎呀! . .尝试只使用curl www.google.com,并以HTML标记“302文档已移动”的形式给出如下输出,我也无法从终端对应用程序本身进行ping,但它是可以公开访问的

So cron job getting executed is out of question :P

所以cron作业被执行是毫无疑问的P