crontab with wget - why is it running twice?

帅比萌擦擦* 提交于 2019-12-09 08:13:49

问题


I've a php script which runs from webservice and insert to DB.

crontab -e

......other cron tasks above.......
...
..
..
# Run test script.php at 1610
10 16 * * * /usr/bin/wget -q -O /home/username/my_cronjobs/logs/cron_adhoc http://localhost/project/script.php

Apparently, at 16:10, this script is run twice! 16:10:01 and 16:25:02

Is it something wrong and gotta do with using wget?? Or did i set the schedule on cron job wrongly?

When i run http://localhost/project/script.php from browser, it will only run once..

Any idea regarding this problem ?

I've tested, there are no other users running the same job... I suspect the way wget works.

As my script needs at least 20mins to complete without sending back a response (it is pulling alot of data from webservicces and save to db) .. suspect there's a time out or retry of wget by default causing this problem.


回答1:


The wget docs give a default read-timeout of 900 seconds, or 15 minutes.

if, at any point in the download, no data is received for more than the specified number of seconds, reading fails and the download is restarted

This is why you were seeing the file called again 15 minutes later. You can specify a longer read-timeout by adding the parameter and an appropriate number of seconds:

--read-timeout=1800



回答2:


i think i solve my own question.

My php takes some time to load, i guess wget retries or time out after some default specified time.

I solved it by using /usr/bin/php




回答3:


Whose user's crontab is this?

Check if there is another user for which you set up cron job at different time and forgot about it.



来源:https://stackoverflow.com/questions/4458307/crontab-with-wget-why-is-it-running-twice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!