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.

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 19 2025 00:13:41
Script start
Timing: Jan 19 2025 00:13:41
Module start 'layout'
Timing: Jan 19 2025 00:13:41
Module start 'content'
Timing: Jan 19 2025 00:13:42
Module end 'content'
Timing: Jan 19 2025 00:13:42
Script end

Main resources:

Total runtime0.7043 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.0072 588.0234152.6250
Module start 'layout' 0.00720.0034 740.648439.4453
Module start 'content' 0.01050.6922 780.0938546.3828
Module end 'content' 0.70270.0016 1,326.476612.1563
Script end 0.7043  1,338.6328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4882160.0002
Check MTime0.00140.2038160.0001
Mysql Total
Database connection0.00150.206310.0015
Mysqli_queries0.644291.4653540.0119
Looping result0.00050.0642520.0000
Template Total0.666294.620.3331
Template load0.00270.377420.0013
Template processing0.663594.204820.3318
Template load and register function0.00030.038210.0003
states
state_id_array0.00110.155310.0011
state_identifier_array0.00110.158220.0006
Override
Cache load0.00210.2929320.0001
Sytem overhead
Fetch class attribute can translate value0.00050.067920.0002
Fetch class attribute name0.00110.152540.0003
XML
Image XML parsing0.00300.430320.0015
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00400.5688230.0002
String conversion0.00000.001040.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs