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.
Comments
Comment #1
nerdcore commentedI 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.
Comment #2
Anonymous (not verified) commentedI think token should add this extra check.
Patch included.
Comment #3
Anonymous (not verified) commented#2 patch is the life saver. Thanks JesseDP
Comment #4
wroxbox commentedPatch included
Comment #9
dave reidThis needs a parenthesis around the $parent variable assignment, or to move the $plid != $mlid before the $parent assignment (the latter is preferred).
Comment #10
filsterjisah commentedI've added an updated patch with changes suggested by Dave Reid.
Comment #11
anouThanks to filsterjisah. Patch works great.
Comment #12
chris matthews commentedThe 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.
Comment #14
dave reidCommited #10 to 7.x-1.x!