How to get $base_url to show the correct url for my Drupal site when I'm running a cron job? Do I have to set the global $base_url manually for that to happen? Do I have to run the cron job as a registered user?
When I run mysite.com/cron.php by hand everything seems to work fine: $base_url is set to the correct url. However, when I run a similar command via cron or drush, $base_url is set to a generic "http://default".
The funny thing is that when I run cron manually as a registered user from inside Drupal (using devel, for instance), $base_url aways points to the right url.
Any suggestions?
Thanks in advance,
Leo
Your cron is probably set up wrong.
You can use wget or curl, which is effectively the same as running the cron "by hand". Something like this:
5 * * * * wget http://example.com/cron.php
You are probably using drupal.sh, which claims that you should use "http://default/cron.php as the URI." This will break the $base_url handling. The following might work with drupal.sh.
5 * * * * /path/to/drupal.sh --root /home/site/public_html/ http://example.com/cron.php
When using drush, you might have to supply the --uri argument:
drush --uri=http://example.com cron
You could also just set the $base_url variable in settings.php (which is a perfectly valid way to do it, not a hack).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With