PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
gazj
Worker
Worker


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

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

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
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

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

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
Worker
Worker


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

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

i placed it in the bottom of my mainfile.php just before the case for the gfx image
View user's profile Send private message Visit poster's website
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

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

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.
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16976
Location: Kansas

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

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 Visit poster's website AIM Address Yahoo Messenger
gazj
Worker
Worker


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

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

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
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum