I've set up a cron job to wget a PHP script every hour. However, it seems to get stuck in a loop and constantly running. If I run the script in a browser or via the command line it works fine. I've tried using wget and command line PHP and I get the same problem.

Here's my job:

0, 9-18, * * 1-5 wget http://www2.lichfielddc.gov.uk/planning/cron.php
  • Do you have any logfile output from cron? – Sven Apr 21 '11 at 10:33
  • you should check the script and debug it, if it gets stuck in a loop then there's nothing you can do without changing the php script – quamis Apr 21 '11 at 10:56
  • I've tried it with a one line script which just outputs "hello" and I still get the same behaviour – Pezholio Apr 21 '11 at 11:51

Remove the commata from your minute and hour columns. Specify timeouts and retries explicitely like with

0 9-18 * * 1-5 wget -a /tmp/cron.log --tries=1 --timeout=90 http://www.example.com

You may want to add a log during your tests, this is done with -a in the example.

[Edit after comment:]

To get to know that it's not smth. wget specific you could replace your cron command line with a timout command that has a higher duration than the 90secs timeout I added in my example:

timeout --kill-after=110 --signal=15 110 wget -a /tmp/cron.log --tries=1 --timeout=90 http://www.example.com

wget should stop after 90 secs, if not, timeout terminates it after 110 secs. (signal SIGTERM=15 should be sufficient, if not use SIGKILL=9).

  • OK, cool, I've got that now. Checking the log file it seems to be constantly running still. Looking at my log file I just get: Resolving www2.lichfielddc.gov.uk... Connecting to www2.lichfielddc.gov.uk||:80... connected. HTTP request sent, awaiting response... --2011-04-21 12:47:00-- www2.lichfielddc.gov.uk/planning/cron.php Ad infinitum. I've tried it with a test script which just outputs "Hello" and it does the same thing, so it's definitely not my code. – Pezholio Apr 21 '11 at 11:50
  • Yeah, still get the same problem. It's strange because I've got other jobs that run fine? – Pezholio Apr 21 '11 at 13:33
  • 1
    Ok, then try curl instead of wget: curl -m 90 -o /tmp/curl.log www.example.com. – initall Apr 21 '11 at 14:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.