PHPackages                             samdark/sitemap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. samdark/sitemap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

samdark/sitemap
===============

Sitemap and sitemap index builder

3.0.1(2mo ago)5401.4M↓37%93[1 issues](https://github.com/samdark/sitemap/issues)[1 PRs](https://github.com/samdark/sitemap/pulls)20BSD-3-ClausePHPPHP &gt;=7.1CI passing

Since Jun 29Pushed 2mo ago25 watchersCompare

[ Source](https://github.com/samdark/sitemap)[ Packagist](https://packagist.org/packages/samdark/sitemap)[ Docs](https://github.com/samdark/sitemap)[ GitHub Sponsors](https://github.com/samdark)[ Patreon](https://www.patreon.com/samdark)[ RSS](/packages/samdark-sitemap/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (28)Used By (20)

Sitemap
=======

[](#sitemap)

XML Sitemap and XML Sitemap Index builder.

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/12f90de1348b8a87f50e714b2af8434e63272248aada722bf4e0a0f3a3e8bc85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f73616d6461726b2f736974656d61703f736f72743d73656d766572267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/12f90de1348b8a87f50e714b2af8434e63272248aada722bf4e0a0f3a3e8bc85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f73616d6461726b2f736974656d61703f736f72743d73656d766572267374796c653d666c61742d737175617265)[![GitHub Workflow Status (branch)](https://camo.githubusercontent.com/827e99dcbef6c85f403e120a619ed06a7ae5794c65a2bea48d250f004bd5918c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d6461726b2f736974656d61702f7068702e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/827e99dcbef6c85f403e120a619ed06a7ae5794c65a2bea48d250f004bd5918c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d6461726b2f736974656d61702f7068702e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)[![Packagist PHP Version Support](https://camo.githubusercontent.com/f5f32afd755ba17d1be8b1f08835ef5ee061508392d885b3495b945973a23691/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f5f32afd755ba17d1be8b1f08835ef5ee061508392d885b3495b945973a23691/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/a2a4e3ca6d4a66492fba225d0b341ad487d6fcec987ac9253958da40a366bb79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a2a4e3ca6d4a66492fba225d0b341ad487d6fcec987ac9253958da40a366bb79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/024701c9f68bc271c5d4044a5ac32916a56c40de24d6d263fd90085293514df7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265266c6162656c3d746f74616c253230646f776e6c6f616473)](https://camo.githubusercontent.com/024701c9f68bc271c5d4044a5ac32916a56c40de24d6d263fd90085293514df7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265266c6162656c3d746f74616c253230646f776e6c6f616473)[![GitHub](https://camo.githubusercontent.com/7b0916cb05ec70fac85180ce598c99988e494485d0ae0c1ffcd48b66e0012e59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7b0916cb05ec70fac85180ce598c99988e494485d0ae0c1ffcd48b66e0012e59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f73616d6461726b2f736974656d61703f7374796c653d666c61742d737175617265)

Features
--------

[](#features)

- Create sitemap files: either regular or gzipped.
- Create multi-language sitemap files.
- Create sitemap index files.
- Use custom stylesheet.
- Automatically creates new file if either URL limit or file size limit is reached.
- Fast and memory efficient.

Installation
------------

[](#installation)

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
-------------

[](#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('http://example.com/mylink1');
$sitemap->addItem('http://example.com/mylink2', time());
$sitemap->addItem('http://example.com/mylink3', time(), Sitemap::HOURLY);
$sitemap->addItem('http://example.com/mylink4', time(), Sitemap::DAILY, 0.3);

// Set sitemap stylesheet. See example-sitemap-stylesheet.xsl.
$sitemap->setStylesheet('http://example.com/css/sitemap.xsl');

// Write it.
$sitemap->write();

// Get URLs of sitemaps written.
$sitemapFileUrls = $sitemap->getSitemapUrls('http://example.com/');

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

// Add some URLs.
$staticSitemap->addItem('http://example.com/about');
$staticSitemap->addItem('http://example.com/tos');
$staticSitemap->addItem('http://example.com/jobs');

// Set optional stylesheet. See example-sitemap-stylesheet.xsl.
$staticSitemap->setStylesheet('http://example.com/css/sitemap.xsl');

// Write it.
$staticSitemap->write();

// Get URLs of sitemaps written.
$staticSitemapUrls = $staticSitemap->getSitemapUrls('http://example.com/');

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

// Set index stylesheet. See example in repo.
$index->setStylesheet('http://example.com/css/sitemap.xsl');

// Add URLs.
foreach ($sitemapFileUrls as $sitemapUrl) {
    $index->addSitemap($sitemapUrl);
}

// Add more URLs.
foreach ($staticSitemapUrls as $sitemapUrl) {
    $index->addSitemap($sitemapUrl);
}

// Write it.
$index->write();
```

Multi-language sitemap
----------------------

[](#multi-language-sitemap)

```
use samdark\sitemap\Sitemap;

// Create sitemap.
// Be sure to pass `true` as second parameter to specify XHTML namespace.
$sitemap = new Sitemap(__DIR__ . '/sitemap_multi_language.xml', true);

// Set URL limit to fit in default limit of 50000 (default limit / number of languages).
$sitemap->setMaxUrls(25000);

// Add some URLs.
$sitemap->addItem('http://example.com/mylink1');

$sitemap->addItem([
    'ru' => 'http://example.com/ru/mylink2',
    'en' => 'http://example.com/en/mylink2',
], time());

$sitemap->addItem([
    'ru' => 'http://example.com/ru/mylink3',
    'en' => 'http://example.com/en/mylink3',
], time(), Sitemap::HOURLY);

$sitemap->addItem([
    'ru' => 'http://example.com/ru/mylink4',
    'en' => 'http://example.com/en/mylink4',
], time(), Sitemap::DAILY, 0.3);

// Set stylesheet. See example-sitemap-stylesheet.xsl.
$sitemap->setStylesheet('http://example.com/css/sitemap.xsl');

// Write it.
$sitemap->write();
```

Options
-------

[](#options)

There are methods to configure `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.
- `setMaxBytes($number)`. Sets maximum size of a single site map file. Default is 10MiB which should be compatible with most current search engines.
- `setBufferSize($number)`. Sets number of URLs to be kept in memory before writing it to file. Default is 10. Bigger values give marginal benefits. On the other hand when the file size limit is hit, the complete buffer must be written to the next file.
- `setUseIndent($bool)`. Sets if XML should be indented. Default is true.
- `setUseGzip($bool)`. Sets whether the resulting sitemap files will be gzipped or not. Default is `false`. `zlib` extension must be enabled to use this feature.
- `setStylesheet($string)`. Sets the `xml-stylesheet` tag. By default, tag is not generated. See example [example-sitemap-stylesheet.xsl](/example-sitemap-stylesheet.xsl)

There is a method to configure `Index` instance:

- `setUseGzip($bool)`. Sets whether the resulting index file will be gzipped or not. Default is `false`. `zlib` extension must be enabled to use this feature.
- `setStylesheet($string)`. Sets the `xml-stylesheet` tag. By default, tag is not generated. See example [example-sitemap-stylesheet.xsl](/example-sitemap-stylesheet.xsl)

Running tests
-------------

[](#running-tests)

In order to run tests perform the following command:

```
composer test
```

Running PHPStan
---------------

[](#running-phpstan)

In order to check code with PHPStan perform the following command:

```
composer phpstan
```

Running Rector
--------------

[](#running-rector)

In order to check code with Rector perform the following command:

```
composer rector
```

In order to apply Rector changes run:

```
composer rector:fix
```

Running benchmarks
------------------

[](#running-benchmarks)

The benchmark suite uses PHPBench to measure typical sitemap generation workflows from the examples above for small, medium and large websites: content sitemap generation, static sitemap generation, multi-language sitemap generation and sitemap index generation.

```
composer bench
```

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity62

Solid adoption and visibility

Community43

Growing community involvement

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 53.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~219 days

Recently: every ~417 days

Total

19

Last Release

69d ago

Major Versions

1.0.0 → 2.0.02015-07-03

2.2.1 → 3.0.0.x-dev2021-07-02

2.5.0 → 3.0.12026-04-25

PHP version history (4 changes)1.0.0PHP &gt;=5.4.0

2.0.4PHP &gt;=5.3.0

3.0.0.x-devPHP &gt;=7.1.0

3.0.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc29e4e7068a00fe9b9db37b8aadda1db6020adcacef810461e47b99c2b150e6?d=identicon)[samdark](/maintainers/samdark)

---

Top Contributors

[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (37 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (5 commits)")[![ParitoshBh](https://avatars.githubusercontent.com/u/11397869?v=4)](https://github.com/ParitoshBh "ParitoshBh (4 commits)")[![terales](https://avatars.githubusercontent.com/u/1920639?v=4)](https://github.com/terales "terales (3 commits)")[![craftyshaun](https://avatars.githubusercontent.com/u/774763?v=4)](https://github.com/craftyshaun "craftyshaun (3 commits)")[![WinterSilence](https://avatars.githubusercontent.com/u/3521094?v=4)](https://github.com/WinterSilence "WinterSilence (3 commits)")[![atailouloute](https://avatars.githubusercontent.com/u/11352491?v=4)](https://github.com/atailouloute "atailouloute (2 commits)")[![DavidGoodwin](https://avatars.githubusercontent.com/u/203929?v=4)](https://github.com/DavidGoodwin "DavidGoodwin (2 commits)")[![mougrim](https://avatars.githubusercontent.com/u/1057709?v=4)](https://github.com/mougrim "mougrim (1 commits)")[![jakubskrz](https://avatars.githubusercontent.com/u/6973533?v=4)](https://github.com/jakubskrz "jakubskrz (1 commits)")[![raulr](https://avatars.githubusercontent.com/u/682507?v=4)](https://github.com/raulr "raulr (1 commits)")[![rdeanar](https://avatars.githubusercontent.com/u/1760493?v=4)](https://github.com/rdeanar "rdeanar (1 commits)")[![fr05t1k](https://avatars.githubusercontent.com/u/2131624?v=4)](https://github.com/fr05t1k "fr05t1k (1 commits)")[![Claude](https://avatars.githubusercontent.com/in/2246796?v=4)](https://github.com/Claude "Claude (1 commits)")[![theluk](https://avatars.githubusercontent.com/u/580946?v=4)](https://github.com/theluk "theluk (1 commits)")[![wawan93](https://avatars.githubusercontent.com/u/1741716?v=4)](https://github.com/wawan93 "wawan93 (1 commits)")[![bodograumann](https://avatars.githubusercontent.com/u/1223583?v=4)](https://github.com/bodograumann "bodograumann (1 commits)")[![zinovyev](https://avatars.githubusercontent.com/u/1627048?v=4)](https://github.com/zinovyev "zinovyev (1 commits)")

---

Tags

hacktoberfestphpsitemapSitemap

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/samdark-sitemap/health.svg)

```
[![Health](https://phpackages.com/badges/samdark-sitemap/health.svg)](https://phpackages.com/packages/samdark-sitemap)
```

###  Alternatives

[tackk/cartographer

A PHP sitemap generation tool.

325493.4k3](/packages/tackk-cartographer)[nystudio107/craft-seomatic

SEOmatic facilitates modern SEO best practices &amp; implementation for Craft CMS 5. It is a turnkey SEO system that is comprehensive, powerful, and flexible.

1741.5M58](/packages/nystudio107-craft-seomatic)[novactive/ezseobundle

Novactive eZ SEO Bundle is an Ibexa Platform bundle for SEO simplications. metas, sitemaps, robots.txt, etc.

29259.4k3](/packages/novactive-ezseobundle)[rainlab/sitemap-plugin

Sitemap plugin for October CMS

2282.4k1](/packages/rainlab-sitemap-plugin)[fof/sitemap

Generate a sitemap

1899.7k2](/packages/fof-sitemap)[werkspot/sitemap-bundle

Bundle for generating dynamic sitemap.xml content with support for multiple sections

12186.9k](/packages/werkspot-sitemap-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
