- compile locking by touching old compiled files to avoid concurrent compilations

This commit is contained in:
Uwe.Tews
2010-03-31 16:23:01 +00:00
parent 24d5ad78f3
commit b52e9f1ac8
7 changed files with 278 additions and 280 deletions

View File

@@ -1,3 +1,6 @@
31/03/2010
- compile locking by touching old compiled files to avoid concurrent compilations
29/03/2010
- bugfix allow array definitions as modifier parameter
- bugfix observe compile_check property when loading config files

View File

@@ -129,6 +129,8 @@ class Smarty extends Smarty_Internal_Data {
public $force_compile = false;
// check template for modifications?
public $compile_check = true;
// locking concurrent compiles
public $compile_locking = true;
// use sub dirs for compiled/cached files?
public $use_sub_dirs = false;
// compile_error?

View File

@@ -205,18 +205,26 @@ class Smarty_Internal_Config {
// load compiler
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
}
// compile locking
if ($this->smarty->compile_locking) {
if ($saved_timestamp = $this->getCompiledTimestamp()) {
touch($this->getCompiledFilepath());
}
}
// call compiler
if ($this->compiler_object->compileSource($this)) {
try {
$this->compiler_object->compileSource($this);
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && $saved_timestamp) {
touch($this->getCompiledFilepath(), $saved_timestamp);
}
throw $e;
}
// compiling succeded
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
// make template and compiled file timestamp match
touch($this->getCompiledFilepath(), $this->getTimestamp());
} else {
// error compiling template
throw new Exception("Error compiling template {$this->getConfigFilepath ()}");
return false;
}
}
/*
@@ -255,6 +263,6 @@ class Smarty_Internal_Config {
}
}
}
}
}
?>
?>

View File

@@ -14,7 +14,6 @@
* Main config file compiler class
*/
class Smarty_Internal_Config_File_Compiler {
public $compile_error = false;
/**
* Initialize compiler
*/
@@ -59,12 +58,6 @@ class Smarty_Internal_Config_File_Compiler {
$parser->doParse(0, 0);
$config->compiled_config = serialize($this->config_data);
if (!$this->compile_error) {
return true;
} else {
// compilation error
return false;
}
}
/**
* display compiler error messages without dying
@@ -107,8 +100,6 @@ class Smarty_Internal_Config_File_Compiler {
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
}
throw new Exception($error_text);
// set error flag
$this->compile_error = true;
}
}

View File

@@ -1,18 +1,18 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Compiler Base
*
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
* Smarty Internal Plugin Smarty Template Compiler Base
*
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
require_once("smarty_internal_parsetree.php");
/**
* Class SmartyTemplateCompiler
*/
* Class SmartyTemplateCompiler
*/
class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase {
/**
* Initialize compiler
@@ -43,7 +43,7 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace();
// get tokens from lexer and parse them
while ($this->lex->yylex() && !$this->abort_and_recompile) {
if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token ".htmlentities($this->lex->value)."</pre>";
if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " . htmlentities($this->lex->value) . "</pre>";
$this->parser->doParse($this->lex->token, $this->lex->value);
}
@@ -59,15 +59,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
list($_open_tag, $_data) = array_pop($this->_tag_stack);
$this->trigger_template_error("unclosed {" . $_open_tag . "} tag");
}
if (!$this->compile_error) {
// return compiled code
// return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
return $this->parser->retvalue;
} else {
// compilation error
return false;
}
}
}

View File

@@ -1,18 +1,18 @@
<?php
/**
* Smarty Internal Plugin Template
*
* This file contains the Smarty template engine
*
* @package Smarty
* @subpackage Templates
* @author Uwe Tews
*/
* Smarty Internal Plugin Template
*
* This file contains the Smarty template engine
*
* @package Smarty
* @subpackage Templates
* @author Uwe Tews
*/
/**
* Main class with template data structures and methods
*/
* Main class with template data structures and methods
*/
class Smarty_Internal_Template extends Smarty_Internal_Data {
// object cache
public $compiler_object = null;
@@ -255,18 +255,28 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
$this->smarty->loadPlugin($this->resource_object->compiler_class);
$this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty);
}
// compile locking
if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated) {
if ($saved_timestamp = $this->getCompiledTimestamp()) {
touch($this->getCompiledFilepath());
}
}
// call compiler
if ($this->compiler_object->compileTemplate($this)) {
try {
$this->compiler_object->compileTemplate($this);
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated && $saved_timestamp) {
touch($this->getCompiledFilepath(), $saved_timestamp);
}
throw $e;
}
// compiling succeded
if (!$this->resource_object->isEvaluated) {
// write compiled template
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty);
}
} else {
// error compiling template
throw new Exception("Error compiling template {$this->getTemplateFilepath ()}");
return false;
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this);
}
@@ -856,8 +866,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
}
/**
* wrapper for template class
*/
* wrapper for template class
*/
class Smarty_Template extends Smarty_Internal_Template {
}

View File

@@ -50,8 +50,6 @@ class Smarty_Internal_TemplateCompilerBase {
// flag for nochache sections
$this->nocache = false;
$this->tag_nocache = false;
// assume successfull compiling
$this->compile_error = false;
// save template object in compiler class
$this->template = $template;
$this->smarty->_current_file = $this->template->getTemplateFilepath();
@@ -83,7 +81,6 @@ class Smarty_Internal_TemplateCompilerBase {
// call compiler
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
if (!$this->compile_error) {
// return compiled code to template object
if ($template->suppressFileDependency) {
$template->compiled_template = $_compiled_code;
@@ -94,11 +91,6 @@ class Smarty_Internal_TemplateCompilerBase {
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $this->smarty, $template);
}
return true;
} else {
// compilation error
return false;
}
}
/**
@@ -430,8 +422,6 @@ class Smarty_Internal_TemplateCompilerBase {
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
}
throw new Exception($error_text);
// set error flag
$this->compile_error = true;
}
}