Forums / Developer / Possible to cache results of a script?

Possible to cache results of a script?

Author Message

Nicklas Lundgren

Wednesday 21 February 2007 4:03:04 pm

Hi there,

I am working on a project where I use nusoap to deliver information from eZ to other clients.
The script is quite long, and requires a number of seconds to process.

Now I wonder if there is any way I can use eZ caching mechanisms here, to actually cache the results of the processing.

I suppose its hard, since I am writing the script with ordinary php (but with access to the eZ environment). But maybee there is a way?

All suggestions appreciated!

Best regards,
/Nicklas

Nicklas Lundgren, Managing Director
Novitell AB, Sweden

Betsy Gamrat

Tuesday 27 February 2007 8:05:15 pm

Nicklas,

One idea:

Use eZ to generate PHP and have a cronjob write it to a file. Because the content is placed in a PHP file, it is still dynamic, but extracting it out of eZ removes some overhead.

This isn't a simple solution. The basic idea is to create a template that delivers PHP and then call it, through eZ, with a PHP script and write it to a file. This is just a different way of caching - and it allows you full control of the PHP. By removing it from eZ, you remove any template caching overhead.

The code below uses pagelayout to determine whether to deliver the PHP template, which is stripped of headers, etc, or the normal page. A better solution would be an alternate siteaccess, where the whole siteaccess delivers {$module_result.content} without surrounding code/HTML.

I hope this helps. I did use this to support a site that had to withstand burst traffic, where many visitors arrived in a short time-frame.

I have found it is usually easier to get information out of eZ using templates - even using templates to write CSV files, than using PHP.

Your PHP code, could write additional PHP code - and use a cronjob or other mechanism to trigger a refresh.

Good luck.

Template to build PHP

{* Builds PHP to make faster templates *}
<!-- START MAKE PHP OUTPUT -->
<?php

... all the logic to generate the values to support your PHP would go here ...

... this is just sample PHP (after the literal tag) ... yours would be different

{literal}
import_request_variables("gp", "rvar_");
$node = $rvar_node;
$node_name='_'.$node;
echo <<< END
<style type="text/css">
<!--
a {text-decoration:none}
body {background: transparent; font-family: Arial, Helvetica, sans-serif; font-size: 8pt; background: transparent;
 margin: 0; color: #666;}
-->
</style>
END;
if (count($$node_name)==0)
echo 'No<br>';
else
foreach($$node_name as $v)echo $v.'<br>';
?><!-- END MAKE PHP OUTPUT -->
{/literal}

<b>pagelayout.tpl</b>

{let time_class=fetch( 'class', 'list', hash( 'class_filter', array( 'php' ) ) )}
{section show=$module_result.content_info.class_id|ne($php.0.id)}

 ... This is the code that delivers the normal site pages

{section-else}

... This is the code that delivers the PHP pages.  

{literal}
<style type="text/css">
<!--
a {text-decoration:none}
body {font-family: Arial, Helvetica, sans-serif; font-size: 0.6em; background: transparent; margin: 5; color: #666
;}
-->
</style>
{/literal}
<body>
{$module_result.content}
</body>
{/section}

<b>build.php</b>

<?php
$url="http://".$domain.".example.com/ez/index.php/plain/".$make_php_urlalias;
$handle=@fopen($url,"rb");

/* $handle can then be used to read the PHP and write it out */

<b>cronjob</b> executes this command

/usr/local/bin/php -C www/admin/build.php business

I apologize if I misunderstood your request. The idea of this approach is to use eZ to write the PHP that can deliver some eZ content.

eZ debug

Timing: Jan 31 2025 04:17:38
Script start
Timing: Jan 31 2025 04:17:38
Module start 'content'
Timing: Jan 31 2025 04:17:38
Module end 'content'
Timing: Jan 31 2025 04:17:38
Script end

Main resources:

Total runtime0.1142 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 587.9531180.8281
Module start 'content' 0.00530.0068 768.781398.0078
Module end 'content' 0.01210.1020 866.7891526.5781
Script end 0.1141  1,393.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00322.7690200.0002
Check MTime0.00131.0970200.0001
Mysql Total
Database connection0.00080.663910.0008
Mysqli_queries0.074565.22361410.0005
Looping result0.00090.78191390.0000
Template Total0.101689.010.1016
Template load0.00080.659510.0008
Template processing0.100988.341310.1009
Override
Cache load0.00050.460110.0005
Sytem overhead
Fetch class attribute can translate value0.00050.425610.0005
XML
Image XML parsing0.00020.210310.0002
General
dbfile0.00736.4241200.0004
String conversion0.00000.003630.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs