1 (edited by 2005-11-24 15:46:50)

Topic: Improve CuteNews Performance by Adding Page Caching

Pretty easy to add page caching and it makes a world of difference to your server when hosting cutenews and to your visitors! Open your main index script, say index.php and add this the code to very top before ANYTHING else.  Point filemtime to wherever you keep comments.txt. The reason we point to comments.txt is to provide a simple means to determine when to refresh the cache copy on the client side. Personally I produce a dummy.txt file whenever a comment or news is added and point to that. But this is sufficent for most cases to get rolling.


<?php
header("Cache-Control: must-revalidate"); 
header("Pragma: cache");

$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);

$mtime = filemtime("./cutenews/data/comments.txt");
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

if ($if_modified_since == $gmdate_mod) {
    header("HTTP/1.0 304 Not Modified");
    die();
}
header("Last-Modified: $gmdate_mod");
?>

Now we need a simple means to refresh the cache in case of a news post instead of a comment.  The easist way to do this is edit addnews.mdu at the very bottom where you find:

  msg("info","News added", "The news item was successfully added.</br>$unapproved_status_msg");

Add this right below this:

 touch("./data/comments.txt");

Now you have a easy and fairly decent page caching setup for cutenews that will boost performance.

Re: Improve CuteNews Performance by Adding Page Caching

Thanks
I am using this method now..
Great difference when opening pages too.

Re: Improve CuteNews Performance by Adding Page Caching

Someone told me there is a bug with IE cache and you need to add "must-revalidate" in the cache control header or IE will NOT refresh the page like Netscape/Firefox does.

Re: Improve CuteNews Performance by Adding Page Caching

I believe this bug was fixed in IE7, I am not sure it is present in IE6, which most users use now...

5 (edited by 2005-11-16 17:13:59)

Re: Improve CuteNews Performance by Adding Page Caching

 $update_file = fopen("./data/comments.txt", "a+");
 flock($update_file, 2);
 flock($update_file, 3);
 fclose($update_file);


better solution is using

 touch("./data/comments.txt")

all in all, this is really a helpful tuning to your site and server performance

6 (edited by 2005-11-17 07:53:34)

Re: Improve CuteNews Performance by Adding Page Caching

I am thinking it is perhaps wiser to send the Last-Modified header before reading HTTP_IF_MODIFIED_SINCE.

 <?php
header("Cache-Control: cache, must-revalidate");
header("Pragma: cache");
header("Last-Modified: $gmdate_mod");

$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
$mtime = filemtime("./cutenews/data/comments.txt");
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

if ($if_modified_since == $gmdate_mod) {
header("HTTP/1.1 304 Not Modified");
die();
}
?>

Re: Improve CuteNews Performance by Adding Page Caching

Doing more testing I found Firefox doesn't always revalidate its cache, so if a partial page is returned Firefox will continue displaying it and won't revalidate if reloaded untill the last modified date changes. Work around is to remove cache from the cache control.

<?php
header("Cache-Control: must-revalidate");
header("Pragma: cache");

$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);

$mtime = filemtime("./cutenews/data/comments.txt");
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

if ($if_modified_since == $gmdate_mod) {
header("HTTP/1.0 304 Not Modified");
die();
}
header("Last-Modified: $gmdate_mod");
?>

Re: Improve CuteNews Performance by Adding Page Caching

Pretty easy to add page caching and it makes a world of difference to your server when hosting cutenews and to your visitors! Open your main index script, say index.php and add this the code to very top before ANYTHING else.  Point filemtime to wherever you keep comments.txt. The reason we point to comments.txt is to provide a simple means to determine when to refresh the cache copy on the client side. Personally I produce a dummy.txt file whenever a comment or news is added and point to that. But this is sufficent for most cases to get rolling.

<?php
header("Cache-Control: must-revalidate"); 
header("Pragma: cache");

$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);

$mtime = filemtime("./cutenews/data/comments.txt");
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

if ($if_modified_since == $gmdate_mod) {
    header("HTTP/1.0 304 Not Modified");
    die();
}
header("Last-Modified: $gmdate_mod");
?>

Now we need a simple means to refresh the cache in case of a news post instead of a comment.  The easist way to do this is edit addnews.mdu at the very bottom where you find:

  msg("info","News added", "The news item was successfully added.</br>$unapproved_status_msg");

Add this right below this:

 touch("./data/comments.txt");

Now you have a easy and fairly decent page caching setup for cutenews that will boost performance.

Can someone explain how to make the dummy.txt file when news is created

Re: Improve CuteNews Performance by Adding Page Caching

Where are you finding this code? I mean the block that begins with "$update_file". It's not in addnews.mdu, as far as I can tell.


 $update_file = fopen("./data/comments.txt", "a+");
 flock($update_file, 2);
 flock($update_file, 3);
 fclose($update_file);


better solution is using

 touch("./data/comments.txt")

all in all, this is really a helpful tuning to your site and server performance


Re: Improve CuteNews Performance by Adding Page Caching

Where are you finding this code? I mean the block that begins with "$update_file". It's not in addnews.mdu, as far as I can tell.


No, i think BadDog first wrote:

$update_file = fopen("./data/comments.txt", "a+");
flock($update_file, 2);
flock($update_file, 3);
fclose($update_file);

but then Flexer come up with a better idea, so BadDog then edited his first post. So dont care about it, just do whats written in post #1

http://cutephp.com/forum/style_emoticons/default/wink.gif

This hack works great on my own server, but im haveing problems on an other.. Dont know why, guess its a server-related problem http://cutephp.com/forum/style_emoticons/default/tongue.gif  (On the one with problems I have disabled comments, maybe thats why..? )

Re: Improve CuteNews Performance by Adding Page Caching

OK, then. I've edited my files and seem to be having no problems. I have no idea if it's sped up my server response, though.

No, i think BadDog first wrote:but then Flexer come up with a better idea, so BadDog then edited his first post. So dont care about it, just do whats written in post #1

http://cutephp.com/forum/style_emoticons/default/wink.gif

This hack works great on my own server, but im haveing problems on an other.. Dont know why, guess its a server-related problem http://cutephp.com/forum/style_emoticons/default/tongue.gif  (On the one with problems I have disabled comments, maybe thats why..? )


Re: Improve CuteNews Performance by Adding Page Caching

...add this the code to very top before ANYTHING else...

even before the <!DOCTYPE - decleration??

Re: Improve CuteNews Performance by Adding Page Caching

even before the <!DOCTYPE - decleration??


yes. thats right!

Re: Improve CuteNews Performance by Adding Page Caching

Thank you

Re: Improve CuteNews Performance by Adding Page Caching

I have some questions

1. Does it only have to put on index.php? Not on 'news.php' (which shows my last 25 news posts instead of 12) or 'archive.php'?

2. What does it really do? Doesn't it load the comments.txt or something when you refresh the page?

3. Does it work with al browsers?

Re: Improve CuteNews Performance by Adding Page Caching

I have some questions

1. Does it only have to put on index.php? Not on 'news.php' (which shows my last 25 news posts instead of 12) or 'archive.php'?

2. What does it really do? Doesn't it load the comments.txt or something when you refresh the page?

3. Does it work with al browsers?

1) Put it on every site that you want to load faster (most people only include news in the index.php-file)
2) The script tells the browser to use the old cache of that page.. so the server dosn't have to re-generate that spesific page. But if someone have posted a new article/comments the users ofcourse want to update the page. So it only re-load comments.txt if there have been any changes http://cutephp.com/forum/style_emoticons/default/smile.gif
3) It works with the most common browsers (browser that can handle cookies), such as Internet Explorer, FireFox, Opera, Netscape... I dont know if it works with non-graphic browsers, such as Lynx..?

Re: Improve CuteNews Performance by Adding Page Caching

Does someone have any sort of feedback concerning this method and - say- Google?

Does the bot re-read the site? Does Google-Cache re-index the site?

Re: Improve CuteNews Performance by Adding Page Caching

... does this make your webpage load faster`?

Re: Improve CuteNews Performance by Adding Page Caching

only on slower pc's. And if you're host gives you a low amount of bandwith, this might be a good thing to add to your cutenews.

Re: Improve CuteNews Performance by Adding Page Caching

You are wrong FUNimations:

the site loads instant, because you tell the users web-browser that it can use previous downloaded files. Also, the server gets less work to do.

first time an user visits the site, the hole page have to be downloaded as ordinary. But if no changes has happend, next visit will use the browsers cache http://cutephp.com/forum/style_emoticons/default/smile.gif

Re: Improve CuteNews Performance by Adding Page Caching

I'm trying to install this on my site and I believe I'm doing everything right but it still gives me an error message. I'm using v. 1.3.6 and here's the error.

[codebox]
Warning: filemtime() [function.filemtime]: stat failed for /articles/dummy.txt in /xxxxxx/xxxxxx/xxxxxxx/articles/index.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxx/xxxxxx/xxxxxxx/articles/index.php:7) in /home/webtvdel/public_html/articles/index.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxx/xxxxxx/xxxxxxx/articles/index.php:7) in /home/webtvdel/public_html/articles/index.php on line 109

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxx/xxxxxx/xxxxxxx/articles/index.php:7) in /home/webtvdel/public_html/articles/index.php on line 110

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxx/xxxxxx/xxxxxxx/articles/index.php:7) in /home/webtvdel/public_html/articles/index.php on line 111[/codebox]

I put the x's in myself. I also installed willyps's approve mod which works great but now I can't add that second part of the code to addnews because I replace it with willy's code for the approve mod. I was wondering where that code would go now?

Any help would be greatly appreciated...

Re: Improve CuteNews Performance by Adding Page Caching

what's the original code you need to look for
the code you replaced it with (willy's code)
and what part are you supposed to add for this mod.

23 (edited by 2007-08-25 15:20:11)

Re: Improve CuteNews Performance by Adding Page Caching

This is coming straight from his directions....

I don't remember what the original code was. His website is http://cn.willyps.com/ if you wanted to look at the code.


[codebox]4) Open addnews.mdu file (located in ./inc dir) and search for:

else{ $added_by_email = "none"; }

Right after the line above, delete everything until you reach

}
?>

Copy the code below:

// Admin Approve Mod
require_once("./inc/approve.inc.php");

...and paste it between

else{ $added_by_email = "none"; }

...and...

}
?>[/codebox]

Re: Improve CuteNews Performance by Adding Page Caching

i'll take a look at it tomorrow. (maybe tonight depends on when i'll be home).

Re: Improve CuteNews Performance by Adding Page Caching

No rush... I like the idea of page caching and I think it would help out in the long run. However, I think I did so many mods  http://cutephp.com/forum/style_emoticons/default/laugh.gif  that I can't get this one to work properly.


Thanks man

Posts: 1 to 25 of 49

Pages 1 2 Next

You must login or register to post a reply

CutePHP Forums → Script Feedback and Suggestion → Improve CuteNews Performance by Adding Page Caching