• Martin Ry

    (@martin-ry-mathiasen)


    Hi

    I received this message when trying to see Tree View for posts on midspar.dk.

    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 9664513 bytes) in /var/www/sites/midspar.dk/wp-includes/functions.php on line 3269

    This also caused regular post overview page to fail. This was, however, fixed by deactivating Tree View on post overview screen.

    Any idea on how to fix, so Tree View can be used for posts again?

    https://www.ads-software.com/plugins/cms-tree-page-view/

Viewing 9 replies - 1 through 9 (of 9 total)
  • I am having serious memory issues on a large site as well. I get that same error you do except the php file changes constantly. Site has about 2000 pages.

    I deactivated it and havent seen the error since but still testing…

    So far that looks like the culprit unfortunately. I love this plugin a lot and install it by default on every site I can but I guess it can’t handle bigger sites. I’ll respond if I learn anything else.

    Scott Bowler

    (@scottybowl2)

    Did you ever have any luck debugging/fixing this one? I’m running into the same issue.

    Alternatively, did you discover any other plugins that will do the trick?

    No unfortunately…just doesn’t seem to be able to handle sites with lots of pages. Guess it gets bogged own trying to represent them in wp-admin. I keep it installed, deactivated and updated just to watch it though.

    Scott Bowler

    (@scottybowl2)

    Thanks for the update – hopefully someone else might come along with an answer! Might have to dig into the code to get to the bottom of it, it’s a great plugin and fits exactly what I need

    Scott Bowler

    (@scottybowl2)

    Getting to grips with the code.

    This page is called when opening a parent in the tree: https://yoursite.com/wp-admin/admin-ajax.php?action=cms_tpv_get_childs&view=all&post_type=places&lang=&id=44

    It calls the function cms_tpv_print_childs (in the plugins functions.php file). The first line is:

    $arrPages = cms_tpv_get_pages("parent=$pageID&view=$view&post_type=$post_type");
    	var_dump($arrPages); // added by me for debugging

    This first request loads all the children fine and the output is used in the loop to output the JSON for the tree. This is the area where it starts to eat up the memory until it throws a fatal error.

    If I can optimise this code then hopefully I’ll be able to suggest a fix. Will keep this thread updated – feel free to chip in if you have some suggestions!

    Scott Bowler

    (@scottybowl2)

    Ok – I’ve found what the memory hog is. In function cms_tpv_get_pages the get_posts query is loading all the fields available, which is very resource heavy. If I switch this to load only the “ID” fields then the page loads lightening fast. Possible solution will be to specify which fields are needed by the tree so that it ignores everything else.

    Will give that a shot and see if it fixes the issue and I’ll update this thread accordingly.

    Scott Bowler

    (@scottybowl2)

    We have a fix which is beautifully simple – as is usually the case with these sorts of things! 3 lines of code is all it will take ??

    This has been tested on a custom post type with 76,000+ posts, with the biggest parent having 1,700 children.

    In functions.php, find function cms_tpv_get_pages (around line 1252) and alter the $get_posts_args array so that it includes “fields” => “ids”, as shown below

    $get_posts_args = array(
    		"fields" => "ids", // Memory fix - only get the ids of the post to reduce the memory hog of get_posts
    		"numberposts" => "-1",
    		"orderby" => "menu_order title",
    		"order" => "ASC",
    		// "caller_get_posts" => 1, // get sticky posts in natural order (or so I understand it anyway). Deprecated since 3.1
    		"ignore_sticky_posts" => 1,
    		// "post_type" => "any",
    		"post_type" => $r["post_type"],
    		"xsuppress_filters" => "0"
    	);

    Next go to function cms_tpv_print_childs (around line 1328) and scroll down to around line 1353 and look for the “for” loop:
    for ($i=0, $pagesCount = sizeof($arrPages); $i<$pagesCount; $i++) {

    We need to replace this code:

    $onePage = $arrPages[$i];

    With this code:

    // Start memory fix
    $temp_page_id = $arrPages[$i];
    $onePage = get_post($temp_page_id);
    // End memory fix

    And that’s it! Children load fine – I haven’t tested any of the other functionality, but at least the tree loading is working without a hitch now. Will contact the author of the plugin about this and hopefully it can be an official patch so we don’t have to tinker with core functions.

    I can confirm this fix worked for me on the latest version, 1.2.34

    thanks for the instructions!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Fatal error: Allowed memory size exhausted’ is closed to new replies.