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
|