Re: [Phplib-users] Odd PHPlib WebApp Problem
Brought to you by:
nhruby,
richardarcher
From: Layne W. <la...@dr...> - 2004-05-08 05:56:44
|
Quoth Andrew Crawford: > The table is complicated enough that the users need the column headers=20 > reproduced every 5 or 10 records to make it usable. Originally, I was=20 > generating this view entirely using nested templates. The view took way= =20 > too long to load - over 80 seconds - and monopolized the server's CPU for= =20 > the entire time. Several users even had timeout problems waiting for the= =20 > page to load. Benchmarking revealed almost all of that time was spent in= =20 > the section that output the column headers every few records. Whenever I use nested templates, I hand the nested part off to a clean template object, build the full list, and hand the parsed content back to the primary template object. I often do this several times in one page. The problem is that when you use your global template object, the regular expression tries to replace all known variables on each parse(). The fewer variables used in your nested block, the greater the speed gain of this method. It might be worth a try. I've added a shortcut function to my Template extension class that I call before each nested block to start with a clean loop template object: function unset_vars() { $this->varkeys =3D $this->varvals =3D array(); } Here is a simple sample building the options in a select: $loop_tpl->unset_vars(); $loop_tpl->set_var("option", "\n <option value=3D\"{value}\"{selected}>{text}</option>"); =20 foreach($options as $text =3D> $value) { $loop_tpl->set_var(array( "value" =3D> $value, "text" =3D> $text, "selected" =3D> ((is_array($some_var) and ($value =3D=3D $some_= var)) ? " selected" : ""))); $loop_tpl->parse("options", "option", true); } $tpl->set_var("options", $loop_tpl->get_var("options")); Layne Weathers |