Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions
Author Message
gazj
Worker
Worker



Joined: Apr 28, 2006
Posts: 152
Location: doncaster england

PostPosted: Wed Aug 26, 2009 1:39 am Reply with quote

hey guys i came accross this result by mistake after using this method to compress my html includes in my theme i noticed that the memory usage dropped upta 40% on my site by the time i finished adding it to various places.

Right lets begin

first the function to place in the mainfile.php
Code:
function minit($min) {

   // remove comments
   $min = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $min);
   // remove tabs, spaces, newlines, etc.
   $min = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $min);
   return $min;
}


stay in mainfile and find the function blockfileinc
find:
Code:
    if (empty($content)) {

   $content = _BLOCKPROBLEM2;
    }

below add:
Code:
$content = minit($content);

save and close

open the theme.php and on all the inclides for the html files using this method
Code:
    $tmpl_file = 'themes/'.$ThemeSel.'/story_page.htm';

    $thefile = implode('', file($tmpl_file));
    $thefile = addslashes($thefile);
    $thefile = "\$r_file=\"".$thefile."\";";
    eval($thefile);
    echo $r_file;


above the last line the echo add:
Code:
$r_file = minit($r_file);


all comments and lines are removed reducing the number of lines outputted from these parts edited someone give it a try
 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1123

PostPosted: Wed Aug 26, 2009 7:44 am Reply with quote

Where exactly I should place this function

Code:
function minit($min) { 

   // remove comments
   $min = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $min);
   // remove tabs, spaces, newlines, etc.
   $min = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $min);
   return $min;
}
 
View user's profile Send private message
gazj







PostPosted: Wed Aug 26, 2009 10:23 am Reply with quote

i placed it in the bottom of my mainfile.php just before the case for the gfx image
 
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Wed Aug 26, 2009 7:43 pm Reply with quote

At the cost of CPU cycles. For websites where the page essentially its processed and sent to the user, thus the memory discarded, this doesn't really save much. Page loading time is not worth the expense.

You could easily optimize your external files by removing those spaces... but you lose the flexibility to edit them. I prefer to go for usability and documentation rather than figure out every little trick to compress data.

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Wed Aug 26, 2009 8:53 pm Reply with quote

While I agree with Evaders, it is a good tip if you are running on a system that is memory constrained. Thanks!
 
View user's profile Send private message
gazj







PostPosted: Wed Aug 26, 2009 9:58 pm Reply with quote

Evaders i used this as an alternative to removing them manually it also removes html and css comments im sure there can be many other ways to compress data but this i feel is the best way with out compramising the code and on pages with many hundreds maybe thousands of lines it can reduce the output of lines by around 30% +

Raven im sure you have in your time worked on sites or had site owners with sites on poor hosting and this would be a good way to cut out some of the hanging that comes with memory usage overload and if just 10% of sites on a single server used this method im sure server masters would see a big drop in memory usage
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©