RE: [SMARTY] Long compile time problems
| From: | Josh Johnson | Date: | Mon, 19 Aug 2002 02:22:17 +0000 |
| Subject: | RE: [SMARTY] Long compile time problems | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5750@lists.php.net to get a copy of this message | ||
The only constant I can see in the problem is that the template system
seems to hang when when I change a template file. It's pretty constant
tonight, but it wasn't a problem constantly during the rest of the
development process (this is the fourth week of the project), just
happened maybe twice for an extended period in the past.
Here's how I'm using smarty:
I've got a class that extends the Smarty class, that automatically sets
the plugin_dir, compile_dir, and template_dir, from globals set by a
setup.php file. I initially intended to use a separate derived class for
each section of the site where it might need to change, but since
there's only one section right now, there's only one derived class.
I've got a wrapper script that is included in each html file that needs
templates (its called template_display.php). It includes some necessary
files, sets up the db access, instantiates the derived class, sets a few
globals into template variables, and then $smarty->display()'s the main
template for that page.
I've created 35 plugin functions just for this project (and one
modifier), that handle most of the data retrieval and some helpful
formatting functions for my clients. Initially, they were all included
in one file and registered en mass every time template_display.php was
included, but now they're broken into separate files in the plugins
directory (a result of trying to streamline my scripts so the compile
time would become less).
I've built a couple of admins that add/modify/delete data from a mysql
database, both using templates to build the interface. I've also got
some public pages that use templates and display that data in a
user-friendly way.
That's the full extent of it, aside from writing the plugins, I haven't
done anything out of the ordinary with the code. It runs fine once the
templates compile, and it usually compiles fine, its just that
sometimes, usually for a period of time, when I change a file, the
compile step just seems to hang or probably just take a really long
time. I didn't see this problem in windows or on my dev server (a Linux
box) before I uploaded it to my client's server, where the bug showed up
for an extended period of time last weekend. I moved it back to my dev
server at that point assuming the problem was with their machine, then
moved it back when my client told me that they had somebody abusing
their bandwidth, so I assumed all would be well. I did notice it on my
dev server at least once or twice for brief periods after I moved things
from my client's server. It's become more frequent since I've moved
everything back over to my client's server (I really hope that all makes
sense).
Here's some info on my current environment (mostly from php_info):
PHP Version: PHP Version 4.2.2, built on August 5th 2002 (just the
apache mod from what I can tell, no standalone)
PHP build options: './configure' '--with-mysql' '--with
-apache=../apache_1.3.26' '--enable-track-vars'
Apache Version: Apache/1.3.26
Server: FreeBSD 3.2-RELEASE FreeBSD 3.2-RELEASE #0: Wed Apr 18 14:58:13
PDT 2001
Smarty Version: 2.3.0 (I just upgraded a day or two ago, also saw the
problem with version 2.2.0)
Here's my derived class (the file where it lives is also where I define
the SMARTY_DIR constant):
//extend smarty class to make custom template systems
//for each part of the site
class Smarty_Admin extends Smarty {
function Smarty_Admin(){ #Constructor
global $smarty_template_dir;
global $smarty_compile_dir;
global $smarty_config_dir;
global $smarty_plugins_dir;
$this->template_dir = $smarty_template_dir;
$this->compile_dir = $smarty_compile_dir;
$this->config_dir = $smarty_config_dir;
$this->plugins_dir = $smarty_plugins_dir;
}
}
Here's the contents of template_display.php:
<?
include("include/setup.php"); #Basic setup file,
#contains database info
include($include_dir."sitewide_functions.php"); #Global
functions
/* Database Setup */
include($include_dir."CDBAbstract.php");
$db_object = new CDBMySQL($db_host, $db_username, $db_pass, $db_name);
if($page == "admin"){
include($include_dir."admin_core.php");
}
include($include_dir."smarty_setup.php"); #grab smarty class
$smarty = new Smarty_Admin; #make a new admin template
object
# authorization functions
include($base_dir."auth_include/auth_functions.php");
/* Globals assigned for template use */
$smarty->assign("picture_dir", $picture_dir);
$smarty->assign("admin_image_link", $admin_image_link);
$smarty->assign("show_length", $show_length);
$smarty->assign("site_url", $site_url);
//grab template based on name in html file
$smarty->display("$page.tpl");
?>
Thanks for your help, if there's any more information I can give, let me
know
-- Josh
-----Original Message-----
From: Travis Low [mailto:travis@dawnstar.org]
Sent: Sunday, August 18, 2002 9:09 PM
To: Josh Johnson
Cc: smarty-general@lists.php.net
Subject: Re: [SMARTY] Long compile time problems
If you can reliably reproduce the problem, then please provide some code
samples. The smaller the better. Also provide environment information
(OS, PHP
build, Smarty version, etc.).
cheers,
Travis
Josh Johnson wrote:
> Forgive me if this is out of turn, I'm new to mailing lists in
general,
> as well as to this group.
>
> I've been having a pesky problem with a site I'm developing that I
> couldn't find an answer to in the archives or the docs.
>
> For some reason, intermittently, when I change a template it will take
a
> long time for it to compile. Once it manages to compile, it runs fine.
> It takes so long that the browser will often time out. But it doesn't
> seem consistent. Some days it works speedily in true Smarty form,
other
> days it crawls. I haven't noticed a pattern yet.
>
> When it first happened, I immediately started checking my code and
> making sure the server wasn't overloaded, but it's happened on two
> different UNIX servers (when I was initially developing the site, I
was
> using Windows/Apache and didn't experience the problem), and I've
> streamlined my code. I can't see anything obvious that's causing the
> problem, except that when it happens, it only happens when I'm viewing
a
> page that contains a template that was just changed. It even happens
if
> I remove all of the function calls from a template.
>
> Is there anything that anyone can think of that might cause the
template
> compiler to run slow like this? I'm out of ideas, and willing to try
> anything that might help.
>
> Thanks for your help,
> -- Josh
>
>
>
--
Travis Low
<mailto:travis@dawnstar.org>
<http://dawnstar.org/travis>