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?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:22:42
Script start
Timing: Jan 18 2025 16:22:42
Module start 'layout'
Timing: Jan 18 2025 16:22:42
Module start 'content'
Timing: Jan 18 2025 16:22:43
Module end 'content'
Timing: Jan 18 2025 16:22:43
Script end

Main resources:

Total runtime1.0463 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.1797152.6406
Module start 'layout' 0.00560.0023 741.820339.4766
Module start 'content' 0.00801.0369 781.2969474.0391
Module end 'content' 1.04480.0015 1,255.335912.1250
Script end 1.0463  1,267.4609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3000160.0002
Check MTime0.00120.1182160.0001
Mysql Total
Database connection0.00060.061910.0006
Mysqli_queries0.997795.3526540.0185
Looping result0.00060.0538520.0000
Template Total1.010396.620.5051
Template load0.00190.177120.0009
Template processing1.008496.372520.5042
Template load and register function0.00030.025310.0003
states
state_id_array0.00130.122010.0013
state_identifier_array0.00130.128920.0007
Override
Cache load0.00160.1509370.0000
Sytem overhead
Fetch class attribute can translate value0.00100.096620.0005
Fetch class attribute name0.00090.088220.0005
XML
Image XML parsing0.00020.021120.0001
class_abstraction
Instantiating content class attribute0.00000.000620.0000
General
dbfile0.00070.0717100.0001
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs