SOLVED Compresion GZIP en archivos PHP no funciona

50l3r

Active Member
Mar 3, 2017
43
6
8
Spain
cPanel Access Level
Root Administrator
Buenas tardes,

Escribo este hilo porque estoy chequeando mi sitio y he habilitado la compresion gzip pero hay un problema:

FUNCIONA: - Removed -
NO FUNCIONA: - Removed -

Este es mi archivo .htaccess:

Code:
RewriteEngine on

RewriteBase /

RewriteCond $1 !^(index\.php|assets|revslider|dist|sitemap\.xml|contacto\.php|google359cc7244751e9c3\.html|.well-known|sign\.html|sign_host\.html|sign\.png)
RewriteRule ^(.*)$ index.php/$1 [L]

# php -- BEGIN cPanel-generated handler, do not edit
# Configure el paquete “ea-php70” como el lenguaje de programación predeterminado “PHP”.
<IfModule mime_module>
  AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 256M
   php_value post_max_size 20M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 15M
   php_flag zlib.output_compression On
   php_value output_handler ob_gzhandler
</IfModule>
# END cPanel-generated php ini directives, do not edit
Y este mi php.ini

Code:
; cPanel-generated php ini directives, do not edit
; Manual editing of this file may result in unexpected behavior.
; To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
; For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)

display_errors = Off
max_execution_time = 30
max_input_time = 60
max_input_vars = 1000
memory_limit = 256M
post_max_size = 20M
session.gc_maxlifetime = 1440
session.save_path = "/var/cpanel/php/sessions/ea-php70"
upload_max_filesize = 15M
zlib.output_compression = On
Que puede ocurrir para que no me comprima la web hecha en PHP?
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello @50l3r,

Have you enabled compression using the Optimize Website feature in cPanel? If so, can you confirm the specific method you are using to test if compression is enabled?

Thank you.

Translation:

Hola @50l3r,

¿Ha habilitado la compresión utilizando la función Optimizar sitio web en cPanel? De ser así, ¿puede confirmar el método específico que está utilizando para probar si la compresión está habilitada?

Gracias.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
462
113
UK
cPanel Access Level
Root Administrator
Hola @50l3r,

Remember that the gzip compression does not compress the php file itself, but compresses the output that the php file creates

Look for Content-Encoding: gzip in the page response headers.
-------------
Recuerde que la compresión gzip no comprime el archivo php, sino que comprime la salida que crea el archivo php.

Busque Content-Encoding: gzip en los encabezados de respuesta de la página.
 
  • Like
Reactions: cPanelMichael

50l3r

Active Member
Mar 3, 2017
43
6
8
Spain
cPanel Access Level
Root Administrator
He probado con "optimizar el sitio web" y marcar "todo" pero no funciona

Chequeo en esta pagina web: Check GZIP compression

Si incluyo calltek .es no funciona
Si incluyo calltek .es/sign.html si funciona

I tried to put this line in my php file:

Code:
if(!ob_start("ob_gzhandler")) ob_start();
But it does not work

In phpinfo...

 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello @50l3r,

Can you run the following command for one of your website pages and let us know the output?

Code:
curl -v --compressed http://domain.tld/test.php
Ensure to use CODE tags and replace real domain names and IP addresses with examples when pasting the output in your response.

Thank you.

Hola @ 50l3r,

¿Puedes ejecutar el siguiente comando para una de las páginas de tu sitio web y dejarnos saber el resultado?

Code:
curl -v --compressed http://domain.tld/test.php
Asegúrese de usar etiquetas CODE y reemplace nombres de dominio reales y direcciones IP con ejemplos al pegar el resultado en su respuesta.

Gracias.
 

50l3r

Active Member
Mar 3, 2017
43
6
8
Spain
cPanel Access Level
Root Administrator
Hello @50l3r,

Can you run the following command for one of your website pages and let us know the output?

Code:
curl -v --compressed http://domain.tld/test.php
Ensure to use CODE tags and replace real domain names and IP addresses with examples when pasting the output in your response.

Thank you.

Hola @ 50l3r,

¿Puedes ejecutar el siguiente comando para una de las páginas de tu sitio web y dejarnos saber el resultado?

Code:
curl -v --compressed http://domain.tld/test.php
Asegúrese de usar etiquetas CODE y reemplace nombres de dominio reales y direcciones IP con ejemplos al pegar el resultado en su respuesta.

Gracias.
Code:
* About to connect() to removed.tld port 80 (#0)
*   Trying removed...
* Connected to removed.tld (removed) port 80 (#0)
> GET /index.php HTTP/1.1
> User-Agent: curl/7.29.0
> Host: removed.tld
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 302 Found
< Date: Fri, 14 Sep 2018 00:24:36 GMT
< Server: Apache
< Vary: Accept-Encoding
< Location: https://removed.tld/index.php
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host removed.tld left intact
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello @50l3r,

It looks like the custom redirect rules in your .htaccess file are the culprit. You may want to try temporarily removing the custom redirect rules and then testing again to confirm they are the cause of the issue. If the content is compressed after removing the custom redirect rules, then you'd want to check with a website developer to see how you might adjust those rules to ensure compression still works.

Thank you.
 

50l3r

Active Member
Mar 3, 2017
43
6
8
Spain
cPanel Access Level
Root Administrator
Hello @50l3r,

It looks like the custom redirect rules in your .htaccess file are the culprit. You may want to try temporarily removing the custom redirect rules and then testing again to confirm they are the cause of the issue. If the content is compressed after removing the custom redirect rules, then you'd want to check with a website developer to see how you might adjust those rules to ensure compression still works.

Thank you.
He reducido mi htaccess a esto:

Code:
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 256M
   php_value post_max_size 20M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 15M
   php_flag zlib.output_compression On
</IfModule>
# END cPanel-generated php ini directives, do not edit
Pero sigue sin funcionar correctamente:

Code:
[[email protected] ~]# curl -v --compressed http://removed.tld/index.php
* About to connect() to removed.tld port 80 (#0)
*   Trying removed...
* Connected to calltek.es (removed) port 80 (#0)
> GET /index.php HTTP/1.1
> User-Agent: curl/7.29.0
> Host: calltek.es
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 302 Moved Temporarily
< Date: Fri, 14 Sep 2018 19:05:58 GMT
< Server: Apache
< Vary: Accept-Encoding
< Location: https://removed.tld/index.php
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host removed.tld left intact
 
Last edited by a moderator:

rpvw

Well-Known Member
Jul 18, 2013
1,101
462
113
UK
cPanel Access Level
Root Administrator
I found this in Stackoverflow - you could try adding it to your .htaccess file and seeing if it works !

Encontré esto en Stackoverflow: ¡podrías intentar agregarlo a tu archivo .htaccess y ver si funciona!

Code:
<IfModule mod_deflate.c>
  # force deflate for mangled headers
  # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.c>
    # Legacy versions of Apache
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

<IfModule !mod_deflate.c>
    #Apache deflate module is not defined, active the page compression through PHP ob_gzhandler
    php_flag output_buffering On
    php_value output_handler ob_gzhandler
</IfModule>
 

50l3r

Active Member
Mar 3, 2017
43
6
8
Spain
cPanel Access Level
Root Administrator
I found this in Stackoverflow - you could try adding it to your .htaccess file and seeing if it works !

Encontré esto en Stackoverflow: ¡podrías intentar agregarlo a tu archivo .htaccess y ver si funciona!

Code:
<IfModule mod_deflate.c>
  # force deflate for mangled headers
  # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.c>
    # Legacy versions of Apache
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

<IfModule !mod_deflate.c>
    #Apache deflate module is not defined, active the page compression through PHP ob_gzhandler
    php_flag output_buffering On
    php_value output_handler ob_gzhandler
</IfModule>
Me daba este error en FilterProvider:

Code:
[Sat Sep 15 16:07:24.192677 2018] [core:alert] [pid 5733] [client 62.42.153.102:34825] /home/calltek/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
Conseguí solucionarlo y este es mi htaccess ahora:

Code:
RewriteEngine on

RewriteBase /

RewriteCond $1 !^(index\.php|assets|revslider|dist|sitemap\.xml|contacto\.php|google359cc7244751e9c3\.html|.well-known|sign\.html|sign_host\.html|sign\.png)
RewriteRule ^(.*)$ index.php/$1 [L]

# php -- BEGIN cPanel-generated handler, do not edit
# Configure el paquete “ea-php70” como el lenguaje de programación predeterminado “PHP”.
<IfModule mime_module>
  AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit


# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 64M
   php_value post_max_size 20M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 15M
   php_flag zlib.output_compression On
</IfModule>

<IfModule mod_deflate.c>
  # force deflate for mangled headers
  # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

   # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/html'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/css'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/plain'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/x-component'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/javascript'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/json'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/xhtml+xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/rss+xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/atom+xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/vnd.ms-fontobject'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'image/svg+xml'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'image/x-icon'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'application/x-font-ttf'"
    FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'font/opentype'"
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.c>
    # Legacy versions of Apache
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

<IfModule !mod_deflate.c>
    #Apache deflate module is not defined, active the page compression through PHP ob_gzhandler
    php_flag output_buffering On
    php_value output_handler ob_gzhandler
</IfModule>
Pero lamentablemente sigue sin comprimir
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
462
113
UK
cPanel Access Level
Root Administrator
Gracias por la actualizacion.
Me alegra que hayas encontrado cuál era el problema.
 
  • Like
Reactions: cPanelMichael

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Solucionado. El problema era del propio script no del htaccess
I'm happy to see the issue is solved. Can you share any information about what in-particular about the script caused the problem?

Thank you.

Translation:

Estoy feliz de ver que el problema está resuelto. ¿Puede compartir cualquier información sobre qué en particular sobre el guión causó el problema?

Gracias.
 
Thread starter Similar threads Forum Replies Date
5 Discusión en Español 1
5 Discusión en Español 7