excel export: how to spare memory in tpl ?

Author Message

Seb Gaillard

Wednesday 22 July 2009 12:10:58 pm

Hi,

I want to make an excel export of all content of a class in the same page.
I have some memory limit problem :

<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 120061917 bytes) in <b>/var/www/psycho/var/mySite/cache/template/compiled/partners-68dce9a3d2b5c693cca5f961b1369a56.php</b> on line <b>688</b><br />

my excel file is generated by clicking on a link like this

<a href={concat('layout/set/excel/content/view/partners/(class)/mySite_interview')|ezurl()}>Interview</a>

As there is no possibility to navigate between differents pages (with offset parameter), I try to "simulate" the pagination mechanism like that

{def   $depth= 7
        $parentNodeId = 2
        $counter=0
	$offset=0
	$limit=25
	$filter_hash=true()
     $count = fetch('content','list_count',hash('parent_node_id', $parentNodeId,
								'main_node_only', true(),
								'depth', $depth,
								'class_filter_type', include,
								'class_filter_array', array($view_parameters.class )
								)
					)
     $ForLimit = ceil($count|div($limit))
     }
<html>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<table style="border: 1px solid black">
<tr>
<td colspan="3" style="font-weight: bold; background-color: silver;">
Article [{$count}]
</td>
</tr>
<tr>
    <td></td>
    <td style="font-weight: bold;">Type of content</td>
    <td style="font-weight: bold;">Title</td>
</tr>
{for 0 to $ForLimit}
	{set $offset=$offset|sum($limit)
	$filter_hash=hash('parent_node_id', $parentNodeId,
						'main_node_only', true(),
						'limit', $limit,
						'offset', $offset,
				        'class_filter_type', 'include',
				        'class_filter_array', array( $view_parameters.class ),
				        'depth', $depth,
						)

	}
	{* by creating a new set of $elements, I hope to spare memory*}
        {def $elements=fetch('content','list',$filter_hash)}
	{foreach $elements as $element}
		<tr>
		    {set $counter = inc( $counter )}
		    <td>{$counter}</td>
		    <td>{$element.class_identifier|wash()}</td>
		    <td>{$element.name|wash()}</td>
		</tr>
	{/foreach}
	{* free memory ???*}
	{undef $elements}
{for}
</table>
</html>

But it doesn't work. Someone has a solution?

Max Keil

Wednesday 22 July 2009 4:41:49 pm

Hi Seb,

your last 3 line looks ike this! I see, that you forgot to close the "for" method?

{undef $elements}
{for}
</table>
</html>

For exporting huge information containers, I would prefer to use native PHP functions instead of Template code!

It's also not clean to def the same variable within the {for}{/for}. Use "set" for this and def the variable before the loop.

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Seb Gaillard

Thursday 23 July 2009 12:35:39 am

Hi Max,

Effectively I forgot to close the for method... Now, it work's fine! I think that after a lot of hours with the nose through the code, I didn't see anything...

Otherwise, I create (def) the $elements varliable in each loop because I hope that "{undef}" free memory. Do you know:
1/ If it's true ?
2/ if I use {set ...}, the memory is spared too?

Do you know where can I find an exemple who "use native PHP functions instead of Template code" for doing this ?

Thank's,

Seb

Max Keil

Thursday 23 July 2009 5:43:53 pm

You're right,

undef should be more memory efficient.

native PHP: you can create a simple template fetch function or module which would do the same work for you and generate the html, but much more efficient - because of the loops and fetches.

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 21:42:46
Script start
Timing: Jan 30 2025 21:42:46
Module start 'layout'
Timing: Jan 30 2025 21:42:46
Module start 'content'
Timing: Jan 30 2025 21:42:46
Module end 'content'
Timing: Jan 30 2025 21:42:46
Script end

Main resources:

Total runtime0.0231 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 588.2500151.2266
Module start 'layout' 0.00450.0044 739.4766220.7188
Module start 'content' 0.00890.0127 960.19531,001.9609
Module end 'content' 0.02160.0015 1,962.156337.9922
Script end 0.0231  2,000.1484 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.5973140.0002
Check MTime0.00114.6602140.0001
Mysql Total
Database connection0.00073.168610.0007
Mysqli_queries0.003012.848730.0010
Looping result0.00000.035010.0000
Template Total0.00114.710.0011
Template load0.00083.635610.0008
Template processing0.00021.037010.0002
Override
Cache load0.00062.502710.0006
General
dbfile0.00094.010880.0001
String conversion0.00000.025840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs