mod_deflate is not working for php generated page - php

mod_deflate not working for php generated page. I have Apache v2.4.7 with php v5.5.9 on Ubuntu 14.04.5 (LTS). This module is working for static html pages and other files like CSS, js etc.
here is my php information http://www.hostnology.com/test.php

Only content is deflated, if you use HEAD http verb, there is no content, so no need to deflate it
You can set (or there is) parameter in httpd that activate deflate on some mime type. (no need to deflate jpeg for instance)
if content type is small (like <1k) there no point to deflate (size almost same)

Related

Symfony 3: How to compress a twig rendered sitemap in a response? [duplicate]

This question already has an answer here:
gzip compress dynamic content with symfony2
(1 answer)
Closed 5 years ago.
Say I have a route to return a sitemap.xml file for my site. It is generated by rendering a twig file in a controller.
This file is pretty big and I am wondering how to gzip the result into the response. Is this possible in Symfony 3? If yes, how?
Usually, compression should not be handled by your php code or a framework, but by the http server. You can enable gzip compression in your web server config.
If you're using apache, you can enable mod_deflate for xml files in the configuration. https://httpd.apache.org/docs/2.4/mod/mod_deflate.html
You can also create an .htaccess file in the web folder:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/xml
</IfModule>
Hope that helps

Can't resolve Google pagespeed "Enable compression" point using Yii2

Site in question is http://burghleys.com/
Having trouble trying to improve the Google pagespeed score and says I need to enable compression with a 70% improvement on the JS file for example but I can't make the same improvement at all!
https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fburghleys.com%2F
I have GZIP enabled and use the apache mod_deflate to do so, tested as per http://checkgzipcompression.com/?url=http%3A%2F%2Fburghleys.com%2F
I use yii2 https://github.com/rmrevin/yii2-minify-view plugin to compress my files which generally works really well.
I use the HTML5 boiler plate htaccess file.
I tried manually compressing the JS file but can only reach 25%. CSS is even less yet states i can save 80%.
Any thoughts?
ps. I'm working on the other issues too, wanna get that 99 score.
You do have GZIP enabled for some items but if you follow the link to your js you will see that this resource is not being zipped up.
http://checkgzipcompression.com/?url=http%3A%2F%2Fburghleys.com%2Fminify%2Fb329b2d2ce53b5c6be05decfe5e5d723527a666e.js
Add the following line to your .htaccess
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/xml application/xhtml+xml application/rss+xml application/javascript appliction/x-javascript

Confusion about gzip, is it compressed or not?

Sorry to bother you with a question that seems very well documented, but none of the things I tried was completely satisfying.
My Company switched from a hosting package to a manages Server just last week and I'm still in the process of optimising it.
Now, Googles PageSpeed Insights tell me, it is not compressed, as does GTMetrix. GidNetwork tells me compression works fine.
I have already added
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
to my .htaccess, (as recommended here) which works correctly, other settings I've changed are fine, as well as
zlib.output_compression = On
to my php.ini.
The entire .htaccess and php.ini can be seen at jsFiddle.
Headers sent and received in both Firefox and Chrome claim that compression is happening.
I also created a httpd.conf in my home directory, because none existed on my server yet. Should I move the file somewhere else?
What I really want to know:
Soo... what am I doing wrong? Is it compressed? Is it not? How can I make google 'see' the compression?
Thank you very much for your help.
This should be the function you need, it should automatically generates the headers you need:
http://www.php.net/manual/en/function.gzdecode.php
anyway check your php version because it works only with php 5.4.0 or later ones.
Although my browser accepts deflate/gzip encoding (Accept-Encoding: gzip, deflate), your server does not answer using compressed data:
HTTP/1.1 200 OK
Date: Tue, 11 Mar 2014 09:41:45 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=2, max=200
Etag: "96-100e9-4f4517d791912"
Expires: Fri, 11 Apr 2014 13:28:25 GMT
Cache-Control: max-age=2692000, public
Vary: User-Agent
If it was compressed, the server would send also
Content-Encoding: deflate
Use FireBug or the dev console to see the headers. It must be your httpd.conf.
You cannot simply create this file in your home directory and Apache will load it.
Have a look in /etc/apache* and /etc/httpd/* for config files.
You have already enabled gzip compression but you haven't set it to compress some file types such as javascript and css. That is why Googles PageSpeed was tried to suggest to enable compression. To enble compression for those two types, use
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
What worked for me in the end to compress the js/css files that were left uncompressed for reasons I don't quite get yet is described here.
In this method, javascript and css-files are forcibly gzipped by a php-script. It also sets new "Expire"-Headers, so if you want caching for more than 5 Minutes, change the number. Adding different files is trickier, but possible, I think.

How do I compress imported images?

I've recently imported blog posts from blogger to a wordpress site.
Google page speed is telling me these images should be losslessly compressed.
How do I go about compressing these images if they weren't uploaded by me?
I have 1000+ of these images that are attached to each post and are not part of my media.
They all have links like this http://4.bp.blogspot.com/-CRkcAeqLqFU/UUA5MUbe8MI/AAAAAAAAKcs/ZGi4LFxQ-nQ/s320/Kelly+Rowland.jpg
Here's an example page:
http://lartmagazine.co.uk/whos-loving-kelly-rowlands-new-video/
Hello to make them losslessly compressed there are few tools you can use if you dont have root right to the webhost.
PNGOptimizer - Converts into PNG other lossless image formats (BMP, GIF, TGA).
Platform: Windows
At a tiny 146KB download, PNGOptimizer is the smallest program here, so it's no real surprise that the interface is a little basic. Or that it concentrates on PNG files.
http://psydk.org/PngOptimizer
FileOptimizer
Not only can it compress JPG, GIF and PNG images, but it can also work with executable files, archives, Microsoft Office documents, PDF files, and the list goes on.
http://nikkhokkho.sourceforge.net/static.php?page=FileOptimizer
Other Way is to check your phpinfo
1) Open notepad
2) Write
<?php phpinfo(); ?>
Save as info.php upload to server and see if you have mod_deflate & GZIP on
then upload to your .htaccess file
<IfModule mod_deflate.c>
# html, xml, css, and js:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript application/json
# webfonts and svg:
<FilesMatch "\.(ttf|otf|eot|svg)$" >SetOutputFilter DEFLATE</FilesMatch>
</IfModule>
don't forget to add above the image type i am sure that png can be done only jpegs are already compressed.
Have a great day
From: Shomron David
Hawk-Tech

Having problems with gzip

I have some problems with gzip encoding and I just can't figure them out!
I added in my htaccess "AddOutputFilterByType DEFLATE ... ..." and I used the tool from http://www.gidnetwork.com/tools/gzip-test.php to check if my pages are encoded properly. The tool says everything is ok.
The problem is that when I check the pages with the web developer tools from chrome or firebug, they don't recognize the pages as gzipped. In the headers section the "content-encoding: gzip" does not appear and PageSpeed also says they are not encoded and recommends me to encode them.
Any ideas? Thanks.
Adi Ulici
AddOutputFilterByType is deprecated try AddOutputFilter instead, eg
AddOutputFilter DEFLATE php js css html

Categories