Forums / Setup & design / PHP works in templates! (with viewcaching enabled)

PHP works in templates! (with viewcaching enabled)

Author Message

Mark Overduin

Tuesday 30 December 2003 3:11:52 am

Woohoo, I just found out how to use php with viewcaching enabled!

This is 'the story':

A time ago, I created a function to include parsed php files in templates (more info: http://ez.no/developer/ez_publish_3/documentation/customization/tips_tricks/including_php_files_in_templates).

But, last week I found out it's hardly of no use when you DISable viewcaching (I was editing, so viewcaching was disabled).
So, when you enable caching, you'll always view a cached page (which isn't dynamic).

Today, I found a work-around, to keep your pages cached, but also dynamic!
This is how to do it:

- 'Install' the function in the kernel as I described on the page (link on top of this page)
- Put the template codes in your templates: {"http://www.mydomain.com/file.php"|marksPHPinsert}
- In 'file.php', you should do something like this:

<?php
echo " echo <?php ";
echo " echo rand(0, 100); ";
echo " echo ?> ";
?>

All right. This is it actually. The template-code parser parses the code to php. The output of file.php is 'echo <?php etc...'. The template-code parser puts these lines in a .php file (the cache file), but will put the compiled php code on the screen (only the first time), NOT the cached file. The second time you load your page, ezPublish will load the cached file (which contains the php code) and parse every php code in it.

So, the first time you load your page, a cach file is created, but what you see on the screen, does come out of the cache file, but from the server's memory or something.
The second time (and every next time) you load the page, you will view cached files which contain php code, which of course will be parsed by the php parser.

Example what the server does the first time you load the page:
1. Read template file (the included php file returns php text (not code))
2. Save the output of the template-code parser in a cache file (.php file)
___AND___
put the same output on the screen.

Example what the server does every next time you load the page:
1. Load the cached file
2. Compile it with the php parser

Now, the first time I load the page, my code does not come out of a cache file (which I would like very much) and my 'sneaky-included' php code is not parsed.
The second time I load the page, everything will come out of a cache file, so my php code will be parsed.

It's hard to explain what's going on, so I hope this whole story is clear enough...

Now, my question: Is it possible to ALWAYS view a cached file?

-- Mark

Shurbann Martes

Friday 02 January 2004 7:15:59 am

This is not working here :(

With what version of ez have you tried this?

eZ debug

Timing: Jan 18 2025 11:14:19
Script start
Timing: Jan 18 2025 11:14:19
Module start 'content'
Timing: Jan 18 2025 11:14:20
Module end 'content'
Timing: Jan 18 2025 11:14:20
Script end

Main resources:

Total runtime1.0312 sec
Peak memory usage4,096.0000 KB
Database Queries191

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 587.8594180.8125
Module start 'content' 0.00640.9059 768.6719479.1328
Module end 'content' 0.91230.1188 1,247.8047333.4688
Script end 1.0311  1,581.2734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.4199210.0002
Check MTime0.00160.1591210.0001
Mysql Total
Database connection0.00090.088710.0009
Mysqli_queries0.964593.53391910.0050
Looping result0.00170.16901890.0000
Template Total1.000897.120.5004
Template load0.00220.212420.0011
Template processing0.998696.838920.4993
Template load and register function0.00020.023410.0002
states
state_id_array0.00120.116110.0012
state_identifier_array0.00120.121120.0006
Override
Cache load0.00180.1756370.0000
Sytem overhead
Fetch class attribute can translate value0.00230.226330.0008
Fetch class attribute name0.00120.116420.0006
XML
Image XML parsing0.00060.057030.0002
class_abstraction
Instantiating content class attribute0.00000.000620.0000
General
dbfile0.00320.3121210.0002
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 5

Time used to render debug report: 0.0002 secs