Simple PHP sitemap generator.

2.0.1 2020-02-11 19:00 UTC

This package is auto-updated.

Last update: 2020-07-07 13:28:49 UTC


Build Status codecov.io Minimum PHP Version Latest Stable Version Total Downloads

Library for sitemap generation and submission.

Internally uses SplFixedArrays, thus is faster and uses less memory then alternatives.


Installation with Composer:

composer require icamys/php-sitemap-generator

Usage example:


include "src/SitemapGenerator.php";

// Setting the current working directory to be output directory
// for generated sitemaps (and, if needed, robots.txt)
// The output directory setting is optional and provided for demonstration purpose.
// By default output is written to current directory. 
$outputDir = getcwd();

$generator = new \Icamys\SitemapGenerator\SitemapGenerator('example.com', $outputDir);

// will create also compressed (gzipped) sitemap

// determine how many urls should be put into one file;
// this feature is useful in case if you have too large urls
// and your sitemap is out of allowed size (50Mb)
// according to the standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)

// sitemap file name

// sitemap index file name

// alternate languages
$alternates = [
    ['hreflang' => 'de', 'href' => "http://www.example.com/de"],
    ['hreflang' => 'fr', 'href' => "http://www.example.com/fr"],

// adding url `loc`, `lastmodified`, `changefreq`, `priority`, `alternates`
$generator->addURL('http://example.com/url/path/', new DateTime(), 'always', 0.5, $alternates);

// generate internally a sitemap

// write early generated sitemap to file(s)

// update robots.txt file in output directory or create a new one

// submit your sitemaps to Google, Yahoo, Bing and Ask.com


Run tests with command:

$ ./vendor/bin/phpunit

Run code coverage:

$ ./vendor/bin/phpunit --coverage-html ./coverage


New in 2.0.0:

  • Major code rework
  • No more public properties in generator, using only methods
  • Removed addUrls method in favor of addUrl
  • Fixed bug with robots.txt update
  • Fixed bug in addURL method (empty loc)
  • Unit tests added for quality assurance
  • Updated limits according to sitemaps spec
  • Updated search engines urls
  • Added change frequency validation