Re: [SMARTY] Allowed memory size error (Calendar & smarty)
| From: | Sarah Gray | Date: | Wed, 16 Jun 2004 15:53:29 +0000 |
| Subject: | Re: [SMARTY] Allowed memory size error (Calendar & smarty) | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11466@lists.php.net to get a copy of this message | ||
Hi Messju --
Thank you, that was *exactly* the problem! I could not figure out what
was going on -- but your simple solution, replacing the modifier, did
the trick. I hope this helps others as well -- I couldn't find good
documentation on it when I was searching, but now it will be in the
archives.
Thanks again,
s.
messju mohr wrote:
>
> On Tue, Jun 15, 2004 at 05:51:54PM -0500, Sarah Gray wrote:
> > Hi --
> >
> > I'm getting a weird memory limit error when passing an object by
> > assign_by_ref to my template -- but only using one particular object
> > (the other ones pass just fine, this happens to be the biggest, but, at
> > just under 20k, it's not that big). I've described the problem below in
> > as much detail as I could -- has anyone run into this before? Is this
> > some weird memory leak? Am I passing things around incorrectly?
> >
> > ********************
> >
> > The object I'm passing is an instance of MonthDecorator, adapted from
> > here (http://pearcalendar.sourceforge.net/examples/10.phps) -- basically
> > exactly lifted. Works great in my php scripts before I try to assign it
> > to the template.
> >
> >
> > class MonthDecorator extends Calendar_Decorator {
> > /**
> > * @param Calendar_Month
> > */
> > function MonthDecorator(& $Month) {
> > parent::Calendar_Decorator($Month);
> > }
> > /**
> > // more stuff here
> > }
> >
> > The code I'm using is this:
> > (I have other code in there where I assign the days to $selection, etc.
> > but didn't seem relevant.)
> >
> > $Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
> > $MonthDecorator = new MonthDecorator($Month);
> > $MonthDecorator->build($selection); // where selection is array of day
> > objects
> > $t->assign_by_ref("MD", $MonthDecorator);
> > $t->display('tests/cal.tpl'); // where there is nothing happening on
> > cal.tpl yet at all -- i'm just watching the debugger
>
> let me guess: you don't get the "allowed memory exhausted" when
> debugging is disabled.
>
> this is a problem in the debug_print_var-modifier used by the
> debug-console. if you have circular references inside your objects
> (perhaps MathDecorator pointing to Month and Month pointing to
> MatchDecorator) debug_pring_var runs into an endless loop.
>
> a simple solution: replace the debug_print_var smarty provides with
> your own one:
>
> <?php
>
> function smarty_modifier_debug_print_var($var) {
> ob_start();
> echo '<pre>', htmlspecialchars(var_dump($var)), '</pre>';
> return ob_get_clean();
> }
>
> ?>
>
> > The behaviour is as follows:
> >
> > 1. Often the browser just chokes, displaying:
> > Unable to read URL from host 67.19.16.19: no response from server
> >
> > 2. When it doesn't, either the debug console does not pop up at all
> > (IE6), or it starts writing the debug console on the page (NS7) and then
> > stops with this error:
> >
> > Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0
> > (tried to allocate 40 bytes) in
> > /usr/local/psa/home/vhosts/morchand.com/private/plugins/modifier.debug_print_var.php
> > on line 32
> >
> >
> > ***
> > Other notes are,
> >
> > 1. the template doesn't choke when I send other objects by reference,
> > treats them just fine.
> > 2. If I don't send it to the template, I'm able to use it exactly as I
> > need it -- ie, I've pretty much verified that $MonthDecorator works
> > exactly as I need it from within PHP -- it's when I try to assign it to
> > the template so I can use it there that I run into trouble.
> > 3. print_r($MonthDecorator) shows the object configured as I need it.
> > 4. I've googled this error but haven't come up with much as refers to
> > smarty
> > 5. I changed memory limit in php.ini to 16M from 8M and restarted
> > apached, but behavoiur was same, so I changed it back. Besides, is way
> > less than 8M.
> >
> > **
> >
> > Because there's an error when it tries to read (null) and it chokes the
> > browser I'm wondering if there's some memory bug in smarty / php I'm
> > hitting? Or is it much simpler than that, something I'm passing
> > incorrectly?
> >
> > Thoughts appreciated,
> >
> > s.
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php