Download .zip |
Info | Example | View files (63) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2018-11-22 (1 month ago) | Not yet rated by the users | Total: 74 | All time: 9,267 This week: 301 |
Version | License | PHP version | Categories | |||
g-template-php 1.0.0 | BSD License | 5 | PHP 5, Templates, Code Generation |
Description | Author | |
This package can process and render templates generating PHP code. |
Ultrafast and light compiling template engine for PHP5 + Zend OpCache
The sources are based on TemplateLite (http://templatelite.sourceforge.net/) and Smarty (http://www.smarty.net/)
Basically G-Template Engine wants to be a bare minimal smarty alternative. This is the first public techpreview so use it on your own risk!
In the first words i need to say sorry for my bad englis :( I think Smarty is the best template engine for PHP but sometimes it's too slow or eats a lot of memory. Some years ago I found the TemplateLite engine. It is much faster and it doesn't need a lot of memory. But TemplateLite is very old, unsupported and Buggy.
In the first days I just fixed some bugs and cleaned the codes in the TemplateLite sources. After that I wanted to know how much faster and "lighter" TemplateLite than Smarty2 and Smarty3. So I've created some test templates with foreach, section, config file, includes and a lot of assigns from PHP. Because Smarty3 is backward compatible with Smarty2 and TemplateLite is based on Smarty2 the three template engine can use the same tpl files.
After some tests I've noticed that the main bottleneck is the slow IO and the slow file operations. If I move the template resources to memcache or something else I need to give up the power of OpCaches.
The builtin OpCache do some filesystem caching and OptIns but it wasn't enough for me :)
In the latest 7.0.4 version I found the solution: the opcache_is_script_cached() and opcache_compile_file() functions
Smarty do a lot of file_exists and filemtime() queries to the filesystem to validate the compiled resource against the tpl file. So If you fetch a compiled template the Zend OpCaches saves the binary opcodes into the memory. If you modify the compiled resource file the OpCache invalidates the currently cached opcode. With the opcache_is_script_cached() function I can make a function that tells me that the compiled resource file is modified since the last use or not. But I need to compare the tpl file against the compiled resource. So with opcache_compile_file() I can move the tpl files to the OpCache and if the tpl file modified the OpCache invalidates the cached one. So If I check the tpl file with the opcache_is_script_cached() function and it gives me a big false I check the filemtimes and if needed recompile the tpl file into php and with the opcache_compile_file function i can move the tpl file into the cache again.
In the TemplateLite sources I replaced the filemtime based comparsions with this OpCache based hack and TemplateLite gives me a 100% speed boost! If I use a lot of concurent connections in the ab (apache benchmark) smarty gets extremly slower but with this hack isnt :)
in this repo you can find my TemplateLite fork patched with this hack.
Files | / | lib |
File | Role | Description | ||
---|---|---|---|---|
internal (16 files) | ||||
plugins (31 files) | ||||
class.compiler.php | Class | Class source | ||
class.config.php | Class | Class source | ||
class.template.php | Class | Class source |
Files | / | lib | / | internal |
File | Role | Description |
---|---|---|
compile.compile_config.php | Example | Example script |
compile.compile_custom_block.php | Example | Example script |
compile.compile_custom_function.php | Example | Example script |
compile.compile_if.php | Example | Example script |
compile.foreach_start.php | Example | Example script |
compile.generate_c...er_debug_output.php | Aux. | Auxiliary script |
compile.include.php | Example | Example script |
compile.inline.php | Example | Example script |
compile.parse_is_expr.php | Example | Example script |
compile.section_start.php | Example | Example script |
debug.beauty_errors.php | Example | Example script |
debug.tpl | Data | Auxiliary data |
template.build_dir.php | Example | Example script |
template.config_loader.php | Example | Example script |
template.destroy_dir.php | Example | Example script |
template.fetch_compile_include.php | Example | Example script |
Files | / | lib | / | plugins |
File | Role | Description |
---|---|---|
block.capture.php | Example | Example script |
block.strip.php | Aux. | Auxiliary script |
compiler.debug.php | Aux. | Auxiliary script |
function.counter.php | Example | Example script |
function.cycle.php | Example | Example script |
function.html_options.php | Example | Example script |
function.html_select_date.php | Example | Example script |
function.html_select_time.php | Example | Example script |
function.mailto.php | Example | Example script |
function.math.php | Example | Example script |
inlinemodifier.capitalize.php | Aux. | Auxiliary script |
inlinemodifier.cat.php | Example | Example script |
inlinemodifier.default.php | Example | Example script |
inlinemodifier.lower.php | Aux. | Auxiliary script |
inlinemodifier.strip.php | Aux. | Auxiliary script |
inlinemodifier.upper.php | Aux. | Auxiliary script |
modifier.count_characters.php | Aux. | Auxiliary script |
modifier.count_paragraphs.php | Aux. | Auxiliary script |
modifier.count_sentences.php | Aux. | Auxiliary script |
modifier.count_words.php | Aux. | Auxiliary script |
modifier.date_format.php | Aux. | Auxiliary script |
modifier.debug_print_var.php | Aux. | Auxiliary script |
modifier.escape.php | Aux. | Auxiliary script |
modifier.indent.php | Aux. | Auxiliary script |
modifier.regex_replace.php | Aux. | Auxiliary script |
modifier.replace.php | Aux. | Auxiliary script |
modifier.spacify.php | Aux. | Auxiliary script |
modifier.string_format.php | Aux. | Auxiliary script |
modifier.truncate.php | Aux. | Auxiliary script |
shared.escape_chars.php | Aux. | Auxiliary script |
shared.make_timestamp.php | Aux. | Auxiliary script |
Files | / | templates |
File | Role | Description |
---|---|---|
footer.tpl | Data | Auxiliary data |
header.tpl | Data | Auxiliary data |
index.tpl | Data | Auxiliary data |
test.conf | Data | Auxiliary data |
test.html_options.tpl | Data | Auxiliary data |
test.if.tpl | Data | Auxiliary data |
test.printout.tpl | Data | Auxiliary data |
test.section.tpl | Data | Auxiliary data |
test.tpl | Data | Auxiliary data |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.