I have a site with some nodes containing PHP code executing a drupal_goto() for temporary redirects (I know it's not best practice). I noticed that this "hangs" the cron: as soon as linkchecker tries to check these nodes, the drupal_goto() gets executed and the cron stops.

This is where I think it goes wrong in linkchecker.module:

function _linkchecker_scan_node_links($nid) {
  $node = node_load(array('nid' => $nid));

Supposedly the node_load executes the PHP code and causes the drupal_goto(), but I'm not sure.

A quick fix was to alter the node's PHP code, to prevent the drupal_goto from being executed while in cron.

if (substr($_SERVER['PHP_SELF'], -8) != 'cron.php') {
  drupal_goto("http://example.com/");
  break;
}

I don't know whether this is really a linkchecker issue, or rather a node_load issue. Any ideas? :)

Comments

hass’s picture

Category: bug » support
Status: Active » Fixed

Really, you may be doing something wrong if you use drupal_goto() in a node... :-). I've got a similar issue with the latest release #538004: PHP based content crashes cron, but was able to fix it by moving the custom function to the themes template.php. But this sounds not like your issue...

I suggest you install http://drupal.org/project/path_redirect, unpublish your current PHP node and create a redirect rule in path_redirect. Hope this works for you.

Only as a side note - the issue is partly in node_load. I'm guessing for the reason I have never used drupal_goto() in a node, but the main reason may be that node_load runs all your content filters and PHP eval on the node content. This may conflict with cron if the PHP code is not very clean... PHP mode is really advanced and it's written everywhere that PHP mode may cause issues if not coded correctly... This is not a bug of linkchecker, it's a bug in the way how you use PHP code in a node.

Your example above may work (untested myself) - not sure if SCRIPT_NAME may be saver/better, but I suggest you remove this PHP code/unpublish the node and solve your needs in the "right way" with path_redirect as said above.

hass’s picture

Title: Linkchecker may hang cron when "drupal_goto()" is encountered in a node » PHP evaluator: Linkchecker may hang cron when "drupal_goto()" is encountered in a node
hass’s picture

Title: PHP evaluator: Linkchecker may hang cron when "drupal_goto()" is encountered in a node » Linkchecker may hang cron when "drupal_goto()" is encountered in a node
Issue tags: +PHP evaluator

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

hass’s picture