I've received a PHP Maximum Execution Timeout when trying to edit a node. The timeout is 300 sec (5 min).

The error has occured at various points but most commonly on line 1220 of token.module (7.x-1.5) which is inside the token_menu_link_load_all_parents function:

function token_menu_link_load_all_parents($mlid) {
  $cache = &drupal_static(__FUNCTION__, array());

  if (!is_numeric($mlid)) {
    return array();
  }

  if (!isset($cache[$mlid])) {
    $cache[$mlid] = array();
    $plid = db_query("SELECT plid FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid)\
)->fetchField();
    while ($plid && $parent = token_menu_link_load($plid)) {
      $cache[$mlid] = array($plid => $parent['title']) + $cache[$mlid]; // Line #1220
      $plid = $parent['plid'];
    }
  }

  return $cache[$mlid];
}

This site has a very large and deeply nested Main Menu. I'm unsure at this time what is causing the failure. Clearing caches has not affected performance on this issue.

CommentFileSizeAuthor
#10 2327361-php-timeout-token-1.patch614 bytesfilsterjisah
#4 2327361-php-timeout-token.patch925 byteswroxbox
#2 Infinite_loop_fix.patch822 bytesAnonymous (not verified)

Comments

nerdcore’s picture

Status: Active » Closed (works as designed)

I discovered that there was an infinite loop in that function being caused by a rogue entry in the menu_links table which was listed as parent of itself (mlid=plid). I've corrected the erroneous field in the DB and the site is functional again. Not sure how that happened.

Anonymous’s picture

StatusFileSize
new822 bytes

I think token should add this extra check.
Patch included.

Anonymous’s picture

Status: Closed (works as designed) » Patch (to be ported)

#2 patch is the life saver. Thanks JesseDP

wroxbox’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new925 bytes

Patch included

Status: Needs review » Needs work

The last submitted patch, 4: 2327361-php-timeout-token.patch, failed testing.

Status: Needs work » Needs review

The last submitted patch, 2: Infinite_loop_fix.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: 2327361-php-timeout-token.patch, failed testing.

dave reid’s picture

+++ b/token.module
@@ -1226,7 +1226,7 @@ function token_menu_link_load_all_parents($mlid) {
+    while ($plid && $parent = token_menu_link_load($plid) && ($plid != $mlid)) {

This needs a parenthesis around the $parent variable assignment, or to move the $plid != $mlid before the $parent assignment (the latter is preferred).

filsterjisah’s picture

StatusFileSize
new614 bytes

I've added an updated patch with changes suggested by Dave Reid.

anou’s picture

Status: Needs work » Needs review

Thanks to filsterjisah. Patch works great.

chris matthews’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

The 3 year old patch in #10 to token.module applied cleanly to the latest token 7.x-1.x-dev and works great for me as well.

dave reid’s picture

Status: Reviewed & tested by the community » Fixed

Commited #10 to 7.x-1.x!

Status: Fixed » Closed (fixed)

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