PHP - Gzip
Ive gzipped some static html files and want to send it to the browser but not sure how to approach it
So i have : http://site.com/cache/file.html (14gb) http://site.com/cache/file.html.gz (1kb) I did this but do i still need a header?? <?php if(file_exists('cache/file.html')){ @readfile("cache/file.html"); } ?> Similar TutorialsHi guys, I'll try to be concise. When I use this code (zlib): $xmlFile = 'test.xml'; $data = implode("", file($xmlFile)); $gzdata = gzencode($data, 9); $gzFile = "test.gz"; $fp = fopen($gzFile, "w"); fwrite($fp, $gzdata); fclose($fp); It produces test.gz but when I extract the .gz file I get "test" file (without extension) I need to gzip the xml file (keeping the extension) not only the data (when I extract the gz I should get test.xml back) Is there a way I can do this ? For security reasons I can't use exec() function. Please help! Thanks in advance, Alex I have just googling in order to find out how to do GZIP so that user can load web page faster. n i found some article which stated that i have to put this script only. <?php ob_start( 'ob_gzhandler' ); ?> my question is...is it doing the zip? if it is correct where should i put that script, in every page which is needed to be compressed or inside index page only? thanks in advance hey all now im new to gzip got not much knowledge on it. i was testing my site in seositecheckup and according to the test im asked to compress my html, css and js files and i found this bit of coding on google <?php if(isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start('ob_gzhandler'); else ob_start(); ?> i included this file on top of my pages and then it seemed to compress my my file but it seem we need to set header expire on gzip so how could i set expire on it and could someone tell me what exactly is this coding above compressing i mean is it compressing image and all type of files? I have spent all day trying to get any of these functions to work... I have downloaded heaps of expample and NONE! work.. In the case of Zip Archive the CREATE function will not produce a zip file archive to strat with.. Error message says it's created ok... but a search finds no such file. GZip has the same problem. Bzip2 at least creates a blank zip file (17bytes) but I can't add any files to the Bzip2. I have tried on the localhost with dll's installed and on a comercial web server... Nothing gets created... I have read endless examples and documents on the web... None work.. Any help would be much apreciated. I am being sent an XML feed which needs to be downloaded in a 'compressed way'.
The example I have been given is this:
$url = 'http://myurl.com'; $headers[] = "Accept-Encoding: gzip,deflate"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $data = curl_exec($ch); but the output I am getting is jargon like this with loads of black diamond question marks:� +T��sƒ���-}#v���]K���������HB�$&G�����Y�����'߷s�,�.4֫'?'���9;*9^��>�j~�ǫ}z|hq�J��Գ".o2)~b���U~I| How to a convert it back into XML? Many thanks Edited by samjsharples, 30 September 2014 - 03:49 PM. Is there a way I can readily stream-process a compressed XML file in PHP? Something like this NON WORKING example: Code: [Select] $reader = new XMLReader(); $reader->open(bzopen($planet_file,"r")); while ($reader->read()) { ... See also http://php.net/manual/en/xmlreader.open.php |