Monday, August 11, 2014

Create sitemap.xml.gz using PHP

8/11/2014

In this in post we learn how to generate compressed XML sitemap with php. If some reason Apache does not support gzipping - old version, modules not enabled etc, you can use PHP to generate the compressed XML sitemap. PHP comes with a module of its own to generate gzipped content. Execute phpinfo() and look for the strings "deflate" and "gzip", if you found them, you are ready to start outputting compressed content right away, all you have to do is send the header header('content-type: application/x-gzip') to send the content as a gzipped file.

Following example show you how you can do that:

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

$file_name = 'sitemap.xml';
header('content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$file_name.'.gz"');
$data = "dynamic XML sitemap string goes here";
$gzdata = gzencode($data, 9);
echo $gzdata;

?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top