Memory Issue cause by number of invocations?
-
I’ve got a memory problem that I hope you can help me with. As usual, I am SO grateful for your wonderful plugin and even more so for the fantastic support you provide here …
I’ve got a page that keeps running into an out-of-memory issue. It’s the only page that has this issue. This page executes MLA 14 times … once for each category, with different sort and selection options, plus different headings. Currently, I’m up to 215 MB and I’m concerned that I’ll eventually hit my server’s max of 256 MB.
I have a small PHP file that’s basically a single function invoked by a shortcode. Each time I invoke my shortcode, my function determines which set of MLA parameters to use based on the attachment-category. It then invokes MLA once.
I wanted to make sure that you at least know about this memory issue, agree it’s caused by the number of MLA invocations, and can’t really do anything about it. None of the categories has more than about 20 items in them. And they are all fairly small PDF documents.
I suppose I could break my page into 2 different pages so that I’m only invoking MLA half the number of times or I could have one page that lists the 14 categories and a link to 14 separate pages. Each page only containing the shortcode.
Or maybe you can think of something else I can do.
Thanks … Jeff
Here’s the my PHP code:
add_shortcode('list_docs', 'my_list_docs'); /** * FUNCTIONS */ /** * This action invokes MLA with all the standard parameters * Note that <<<EOV ... EOV uses the PHP "Heredoc" format. * link: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc * * Usage: [list_docs category="attachment category", query_value="value for the query using MLA syntax", itemwidth="item width", numberposts="numberposts" style ="style"] * * It invokes MLA. * All parameters are optional, although it's not overy useful if you don't specify at least category. * mla_itemwidth defaults to "45" (since that's my default for most pages). * The mla_style defaults to "sc-list" (since that's my default for most lists). */ function my_list_docs( $atts, $content = null ) { $a = shortcode_atts( array( 'category' => '', 'query_value' => '', 'item_width' => '45', 'numberposts' => '', 'style' => 'sc-list' ), $atts ); $category = $a['category']; $query_value = $a['query_value']; $item_width = $a['item_width']; $numberposts = $a['numberposts']; $style = $a['style']; $my_shortcode = ""; $my_orderby = ""; $my_query = ""; if ($numberposts <> "") { $numberposts = "numberposts=" . $numberposts; } $basic_mla_value = <<<EOV mla_gallery mla_style="$style" columns=1 attachment_category="$category" post_mime_type=application/pdf link=file mla_item_width="$item_width" $numberposts EOV; switch ($category) { case "Town Hall Statuses": case "Town Hall Meeting Notes": case "Town Hall Agendas": case "Forms": case "Contracts": $my_orderby = ' orderby=title order=ASC'; break; case "Event Flyers": case "Board Agendas": case "Board Minutes": case "Financial Reports": $my_orderby = ' orderby="title" order="DESC" '; break; case "Governing Documents": $my_orderby = ' orderby=meta_value meta_key="my-sort-order" order=ASC '; break; case "Board Resumes": $my_orderby = ' orderby=meta_value meta_key="my-sort-order" order=ASC '; $my_query = <<<EOV meta_query="array( array( 'key' => 'YYYY-MM', 'value' => '$query_value', 'compare' => 'LIKE' ) )" EOV; break; case "Newsletter": $my_orderby = ' orderby=meta_value meta_key="YYYY-MM" order=DESC '; $my_query = <<<EOV meta_query="array( array( 'key' => 'YYYY-MM', 'value' => '$query_value', 'compare' => 'LIKE' ) )" EOV; break; default: $my_orderby = ' orderby=title order=ASC '; } $my_shortcode = "[" . $basic_mla_value . $my_orderby . $my_query . "]"; return do_shortcode($my_shortcode); // return $my_shortcode;
Here’s my invocation:
<p><strong>Town Hall Statuses</strong></p><p>[list_docs category="Town Hall Statuses"]</p> <p><strong>Town Hall Meeting Notes</strong></p><p>[list_docs category="Town Hall Meeting Notes"]</p> <p><strong>Town Hall Agendas</strong></p><p>[list_docs category="Town Hall Agendas"]</p> <p><strong>Forms</strong></p><p>[list_docs category="Forms"]</p> <p><strong>Contracts</strong></p><p>[list_docs category="Contracts"]</p> <p><strong>Board Agendas</strong></p><p>[list_docs category="Board Agendas"]</p> <p><strong>Board Minutes</strong></p><p>[list_docs category="Board Minutes"]</p> <p><strong>Financial Reports</strong></p><p>[list_docs category="Financial Reports"]</p> <p><strong>Governing Documents</strong></p><p></strong></p><p>[list_docs category="Governing Documents"]</p> <p><strong>Event Flyers</strong></p><p>[list_docs category="Event Flyers" ]</p> <p><strong>Board Resumes - 2016-03</strong></p><p></strong></p><p>[list_docs category="Board Resumes" query_value="2016-03"]</p> <p><strong>Board Resumes - 2015-12</strong></p><p>[list_docs category="Board Resumes" query_value="2015-12"]</p> <p><strong>Newsletter - 2015</strong></p><p>[list_docs category="Newsletter" query_value="2015"]</p> <p><strong>Newsletter - 2014</strong></p><p>[list_docs category="Newsletter" query_value="2014"]</p>
I’ll eventually replace the paragraph headings with Spoilers so that only the category names show until the visitor expands the one they want.
- The topic ‘Memory Issue cause by number of invocations?’ is closed to new replies.