homepage Welcome to WebmasterWorld Guest from 54.237.38.30
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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



 
Msg#: 4428911 posted 5:42 am on Mar 14, 2012 (gmt 0)

Hello,

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.

<?php
ob_start();
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!

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4428911 posted 1:08 pm on Mar 14, 2012 (gmt 0)

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.

webnetworkz



 
Msg#: 4428911 posted 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.

lostdreamer



 
Msg#: 4428911 posted 10:54 am on Mar 15, 2012 (gmt 0)

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:

<?php
sleep(100);
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.

webnetworkz



 
Msg#: 4428911 posted 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:

<?php

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

header('ETag: "'.md5($timestamp.$file).'"');
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved