0

On a rather old drupal site (D5) I get a 302 on calling cron.php when doing this via wget or curl. It worked fine for many years (via crontab). If I use a browser for that I get a 200 and a blank page (which is normal) the cron runner runs successfully. After trying to find a solution for a couple of hours it works fine with curl for no apparent reason, but not with wget and only if I run it directly (still 302 with crontab). As I type this I try again just to make sure and now neither wget nor curl work anymore, but running it through the browser still works just fine. Strange.

curl: curl -s http://www.mysite.com/cron.php
wget: wget -O - -q -t 1 http://www.mysite.com/cron.php

Any ideas?

4
  • 1
    Is there anything in the logs? Open includes/common.inc, uncomment module_invoke_all('cron') line in drupal_cron_run() function and try running the cron once again to make sure this is not server related. May 3, 2014 at 18:34
  • 1
    302 is a redirect. What do you get after? Is there any info in the apache log? Also, did you install any new modules that use hook_cron() ?
    – Mike
    May 3, 2014 at 20:23
  • 1
    Just a stab in the dark here, but perhaps the HOST header isn't getting sent and this is a vhost with host matching? Or Drupal is using a sites.php and host requested doesn't match. May 7, 2014 at 17:17
  • The cron command was accessing www.mysite.com which was bound to the same directory as www.mysite.de. Three weeks ago this was changed to a redirect from .com to .de which broke the cron run. I have awarded the bounty to Anil Sagar anyway instead of wasting it. At least did his answer guide my search. Thanks everybody for helping out. May 11, 2014 at 15:02

1 Answer 1

2
+150

302 redirect can happen due to Either server settings or manual redirect inside modules using functions like drupal_goto....

You need to debug to understand the problem.. Here are the steps to find out where it is going wrong...

  • To make sure it's not related to server settings go and comment below line in drupal_cron_run function inside includes/common.inc...

    // module_invoke_all('cron')
    
  • If you cannot able to replicate 302 error then it's for sure some module which is implementing hook_cron is doing above redirect other wise check your .htaccess or server settings to debug more..

  • If you don't see 302 error go and uncomment above code you have commented to debug further...

  • Run below code in any page to understand which are modules implementing hook_cron.....

    Code:

    foreach (module_implements('cron') as $module) {
      drupal_set_message($module);
    }
    
  • Verify all above modules which implements hook_cron doesn't have any redirect code.. Check custom modules in particular...

  • If nothing works.. Use Debugger like XDebug to debug step by step.
3
  • I can not check that today (maybe Friday). Just as a thought: How would this apply if the forward only happens with headless requests, but not with a real browser? May 8, 2014 at 6:04
  • Ideally whether you are making requests from browser or command line or via crontab using wget output should be same... Response can't be different for different mediums.. It's just when it's happening and why it's happening..
    – Anil Sagar
    May 8, 2014 at 6:21
  • cron.php is never executed. The redirect must happen somewhere else. The .htaccess file does nothing unusual... May 11, 2014 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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