0

i want to speed up load pages maked by smarty template,i think gzip is good idea. i see this page (this page) but i dont understand how can use this !

  1. is this best way?
  2. how can active gzip in smarty template?
hashem
  • 1
  • 1
  • 1
    there is an `Install` paragraph in header comment of file on link you posted, read it – Marek Sebera Aug 28 '11 at 08:10
  • i dont understand >>> (Drop into the plugin directory) <<< in the plugin folder exist 41 file ! – hashem Aug 28 '11 at 08:21
  • probably you have to place the file inside plugins directory in source code of your application – Marek Sebera Aug 28 '11 at 08:23
  • i copy function into outputfilter.trimwhitespace.php file but error >> Notice: function call 'load_filter' is unknown or deprecated. in D:\xampp\htdocs\cp\lib_smarty\sysplugins\smarty_internal_wrapper.php on line 57 – hashem Aug 28 '11 at 08:24
  • create new file named `outputfilter.gzip.php` in `sysplugins` folder, then when loading it it will seek the file not a function (afaik) – Marek Sebera Aug 28 '11 at 08:27
  • i maked in folder sysplugins but does not work, i move file into plugin folder and my browser show this error >> Content Encoding Error, The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. – hashem Aug 28 '11 at 09:25

2 Answers2

1

Smarty (since version 3.0) has a new format of loading the internal sys plugins.

Drop the gzip file in the /plugins dir (ie. outputfilter.gzip.php.) And just before the $smarty->display call:

// example
$smarty->loadFilter('output','gzip'); 
$smarty->display('tpl/index.html');
//end

You can't use 'load_filter' anymore.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
user1214334
  • 111
  • 4
0

You will want to take a look at the .htaccess file from http://html5boilerplate.com/. It is all you need, put it at the top directory on your web server and apache takes care of the gzip problem.

If you have a .htaccess file already, you need to merge the two.

Once the .htaccess is uploaded and you want to test whether or not it is working, my best tool is FireBug for FireFox using the Net inspector and looking at the response headers. As a fallback try http://www.whatsmyip.org/http_compression/ it will however require the site to online and publicly available.

CodeReaper
  • 5,988
  • 3
  • 35
  • 56
  • The OP is generating pages dynamically. Those will be exempt from caching by default. On a quick glance, I can see nothing in the boilerplate .htaccess file that would change that (like output buffering directives) Can you elaborate on this? – Pekka Aug 28 '11 at 09:28
  • @Pekka It is my understanding that the .htaccess enables compression and then applies compression based on content-type, so when the smarty template is outputted with text/html apache kicks in and gzips the output (or deflates, if the browser only understands that). I am using this myself with generated content and according to FireFug it is working. – CodeReaper Aug 28 '11 at 09:34
  • it doesn't work like that from within a PHP script. See e.g. http://newestindustry.org/2006/10/03/compressing-php-output/ – Pekka Aug 28 '11 at 09:38
  • @Pekka You are correct that it will not work inside a PHP script, however the PHP script delivers its content to the web server (e.g. apache) and not the client. The web server then delivers the content to the client and the web server can (if it supports it) compress the content. This quote from the link you posted "...can be used to effectively compress content on shared or hosted servers where compression is not enabled within the Web server.", also tells me that compression from within PHP is the route to take when the web server cannot compress the content for you. – CodeReaper Aug 28 '11 at 09:46
  • aaah, interesting! Looks like you are right. I didn't know Apache was able to catch output this way - bobince's answer here confirms it as well: [How do I enable mod_deflate for PHP files?](http://stackoverflow.com/q/2835818) However, when I throw the Boilerplate htaccess into my local web root, and have a sample PHP file output `text/html` as its content type, it doesn't seem to enable compression straight away. I may look into this later and will +1 if I get it working :) – Pekka Aug 28 '11 at 09:55
  • @Pekka You had me nervous there for a bit... :-) If the compression isn't working the most common reasons is that the web server does not support it (like if apache does not have mod_deflate or mod_gzip) or that the client does not support it. – CodeReaper Aug 28 '11 at 10:05
  • Yeah, I'll look into this later. It may have to do with my local Apache configuration. – Pekka Aug 28 '11 at 10:06
  • how can find out, apache support mod_deflate or mod_gzip ? and if support not what is other option to do same work? – hashem Aug 28 '11 at 10:18