Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Manual GZip Encoding
    primarykey
    data
    text
    <p>I was testing my website with Page Speed and the result was around 70/100. Enable Compression was the first and most important factor in slowing it down.</p> <p>I know that I can do that by modifying the php.ini to automatically do that but I was more interested in the manual method (<code>gzencode</code>). </p> <p>The problem is either all browsers fail in opening the website (Firefox: "The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.", Chrome: "303, ERR Content Encoding", etc.) or they display the encoded string.</p> <p>Live Headers shows that the browser accepts the encoding, and the response has the content type set, but it still fails.</p> <pre><code>GET / HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate HTTP/1.1 200 OK Content-Encoding: gzip Content-Length: 5827 Vary: Accept-Encoding </code></pre> <hr> <pre><code>private function _compress($data) { //return trim(preg_replace(array('/\&gt;[^\S ]+/s','/[^\S ]+\&lt;/s','/(\s)+/s'), array('&gt;','&lt;','\\1'), $data)); $supportsGzip = strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false; ob_start(); if ($supportsGzip) { echo gzencode(trim(preg_replace('/\s+/', ' ', $data)), 9); } else { echo $data; } $content = ob_get_contents(); header("content-type: text/html; charset: UTF-8"); header("cache-control: must-revalidate"); $offset = 60 * 60; $expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($expire); header('Content-Length: ' . strlen($content)); header('Vary: Accept-Encoding'); ob_end_clean(); echo $content; } </code></pre> <p>If I change the Content-Encoding to zlib, I get the encoded string:</p> <pre><code>‹������ÕZÿsÛ¶ÿW^‘¥²o‘¨/–-Ë–ÚØ‰_Ôµ•õÚ_v I°I‚!A©j–Öºnçÿb·»%ÍÚë²nëå?‘þ›=€¤L)’,ÛIw&gt;ŸEâxïáƒ÷°ùÞ½O¶Ÿï߇Žtlؼµ·» $kŸ•¶ ã^ã&lt;܃•\¾� Ÿº—\¸Ô6ŒûŽ”^Õ0z½^®WÊ ¿m4ÅjŰ…XÎ’©Ã¦ænS·]#ÌÕF-|8LRPL²ìIÈ»5²-\É\™mô=FÀŒJ5"Ù—RóÝ�³Cý€ÉZ([ÙŠb%¹´YýÑãáîcx}±iD´˜¿KV#4”á§x&gt;¬°à®íÒ ãpÅËæî1øÌ®‘@öm </code></pre> <p>I don’t really care anymore about getting the compression as much as I want to know why its not working.</p> <p>Cheers,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload