Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Having trouble with PHP Dynamic Caching Custom APP I am writing.

Having trouble with PHP Dynamic Caching Custom APP I am writing.



5:42 am on Mar 14, 2012 (gmt 0)


I have the following code, where the output_buffer is started, and then a script is executed. The file that this code is contained in is - file: cachingSystem/server.php.

It is included in the header of all the PHP files worth caching.

include_once($_SERVER["SCRIPT_FILENAME"]); // What should go here? Is this correct for displaying the outcome?
$contents = ob_end_clean(); // What should go here? Is this correct for displaying the outcome?

$md5DUB = @md5($contents);
$md5sum = @file_get_contents($filex); // WHERE $filex contains the already pre-recorded MD5 SUM.

if($md5DUB == $md5sum){ # All the rest of my code goes here # }


The MD5 sum that keeps appearing is the empty / null MD5 of d41d8cd98f00b204e9800998ecf8427e.

I need a way to tell what the MD5 sum of the content on the page that is being requested is through a prepended file at the top.

Thanks everyone!


1:08 pm on Mar 14, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Hi and welcome to WebmasterWorld. This will not work because $_SERVER['SCRIPT_FILENAME'] does not contain what you think it does. It will contain the absolute path to the server.php script.

See here: [php.net...]

To amend this, it would probably make sense to include two files in each php page, one at the top and one at the bottom. In each, you open and close the output buffer respectively.


6:25 pm on Mar 14, 2012 (gmt 0)

Hey Eelixduppy,

Thanks. I figured that would be the solution.

Is it a problem of there being no suitable wrapper for including the files on top of each other?

Either way your time and consideration is very much appreciated.


10:54 am on Mar 15, 2012 (gmt 0)

5+ Year Member

Can I ask what you are trying to do here?
Because it looks like the following flowchart:

1) Run all scripts and create output
2) Check MD5 of newly created output against MD5 of cached output
3) ? Wouldn't really mather

Where would you get any positive caching effects if you are running your scripts anyway?

IE: If you code has only this:

echo "Done";

It will sleep 100 seconds with or without caching enabled.
If you have code that checks millions of rows in your DB, it will still have to do that every single time.

Only differents is that IF something is new, you write it to a file as well.

So this way would actually be slower then just running your original script.


9:05 pm on Mar 24, 2012 (gmt 0)

Hey Everyone,

First I would like to say thanks to Webmaster World for providing such great answers.

What I am trying to build is a caching system on PHP. If it doesn't use ob that is just as well.

It could use the Apache headers, HTTP_IF_MODIFIED_SINCE, HTTP_IF_NONE_MATCH to determine validity of changed time such as:


$timestamp = filemtime($_SERVER['SCRIPT_FILENAME']);
$gmt_mtime = gmdate('r', $timestamp);

header('ETag: "'.md5($timestamp.$file).'"');
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime || str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == md5($timestamp.$file)) { MY Cached file }


Would this answer the question of it being slower than my original script?

In what version of PHP were these HEADERS introduced?

Thanks again Webmaster World

Featured Threads

Hot Threads This Week

Hot Threads This Month