Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


$buf

July 28, 2000

Here we determine whether $buf can instead be built from the $cache_file by checking the following:

  • if cache parameter is set and less than 10, we are forced to skip the cache!
  • if cache file exists and the cache parameter is not set, check if default cache time has not yet expired, for then we can use the cache and we should not update it
  • if cache file exists and cache parameter is set, check if that time has not yet expired, for then we can use the cache and we should not update it
  • if we should not use the cache because it is expired, we'll update it after we executed the module

Thus we can now make the $buf creation conditional to the $read_cache variable, by replacing the line that says:


<?php $buf = $fun ($arglist); ?>

with the the following code:


<?php

if ($read_cache || (!strlen ($buf .= $fun ($arglist)))) { if ($f = fopen ($cache_file, "r")) { while ($str = fgets ($f, 4096)) { $buf .= $str; } fclose ($f); } else $buf .= "<!-- $tag: error - cache is empty //-->\n"; } ?>

Note that the module can force the cache (e.g. when database is down) by returning an empty string (risking the cache has not yet been written, but in any case it does not generate a database error, but here an empty place in the page with an html comment)

The last step is see if we should also update the cache, by continuing to add the following code before return $buf:


<?php

if ($write_cache && ($f = fopen ($cache_file, "w"))) {
    fputs ($f, $buf);
    fclose ($f);
}

?>

Now the parser is done and you can start creating both the res/ and cache/ subdirectories and fill res/ with modules xxx.php which implements the function handle_xxx ($arglist)

The parse_it function
Building your website with cached dynamic modules
Conclusion


Up to => Home / Authoring / Languages / PHP / Dynamic_Modules




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers