Sitemap and sitemap index builder

2.0.3 2016-04-28 23:16 UTC

This package is auto-updated.

Last update: 2024-05-09 23:34:38 UTC


Sitemap and sitemap index builder.



  • Create sitemap files.
  • Create sitemap index files.
  • Automatically creates new file if 50000 URLs limit is reached.
  • Memory efficient buffer of configurable size.


Installation via Composer is very simple:

composer require samdark/sitemap

After that, make sure your application autoloads Composer classes by including vendor/autoload.php.

How to use it

use samdark\sitemap\Sitemap;
use samdark\sitemap\Index;

// create sitemap
$sitemap = new Sitemap(__DIR__ . '/sitemap.xml');

// add some URLs
$sitemap->addItem('', time());
$sitemap->addItem('', time(), Sitemap::HOURLY);
$sitemap->addItem('', time(), Sitemap::DAILY, 0.3);

// write it

// get URLs of sitemaps written
$sitemapFileUrls = $sitemap->getSitemapUrls('');

// create sitemap for static files
$staticSitemap = new Sitemap(__DIR__ . '/sitemap_static.xml');

// add some URLs

// write it

// get URLs of sitemaps written
$staticSitemapUrls = $staticSitemap->getSitemapUrls('');

// create sitemap index file
$index = new Index(__DIR__ . '/sitemap_index.xml');

// add URLs
foreach ($sitemapFileUrls as $sitemapUrl) {

// add more URLs
foreach ($staticSitemapUrls as $sitemapUrl) {

// write it


There are two methods to configre Sitemap instance:

  • setMaxUrls($number). Sets maximum number of URLs to write in a single file. Default is 50000 which is the limit according to specification and most of existing implementations.
  • setBufferSize($number). Sets number of URLs to be kept in memory before writing it to file. Default is 1000. If you have more memory consider increasing it. If 1000 URLs doesn't fit, decrease it.
  • setUseIndent($bool). Sets if XML should be indented. Default is true.

Running tests

In order to run tests perform the following commands:

composer install