PHPackages                             netglue/sitemap-builder - 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. netglue/sitemap-builder

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

netglue/sitemap-builder
=======================

A Simple XML Sitemap generation utility

3.0.0(6mo ago)1121.1k↑103.9%[1 issues](https://github.com/netglue/PHP-Sitemap-Builder/issues)[1 PRs](https://github.com/netglue/PHP-Sitemap-Builder/pulls)MITPHPPHP ~8.2 || ~8.3 || ~8.4 || ~8.5CI passing

Since Jan 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/netglue/PHP-Sitemap-Builder)[ Packagist](https://packagist.org/packages/netglue/sitemap-builder)[ RSS](/packages/netglue-sitemap-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (6)Used By (0)

Another Sitemap Builder Utility in PHP
======================================

[](#another-sitemap-builder-utility-in-php)

Why?
----

[](#why)

It's pretty easy to make an XML sitemap and there's lots of utilities out there, but these tend to concentrate on persisting the xml to disk. If you're running your app on a handful of servers, disks are a pain in the ass.

I wanted something that only generated the XML as a string so that I could easily throw that at a cache, or serialise to files on AWS or Google cloud or whatever.

Install
-------

[](#install)

Install with composer in the normal way…

```
composer require netglue/sitemap-builder
```

This lib requires the xml writer extension, and a minimum of PHP 7.1

Tests
-----

[](#tests)

Coverage is currently 100%, just CD to the project directory and…

```
composer install
vendor/bin/phpunit
```

Usage
-----

[](#usage)

### Single, standalone sitemap

[](#single-standalone-sitemap)

If you have no need of a sitemap index file, i.e. you're never going to have more than 50k URLs, then something like this should suffice:

```
use Netglue\Sitemap\Sitemap;

$sitemap = new Sitemap('some-file.xml', 'https://base-host-and-scheme.com');
$sitemap->addUri('/somewhere');

$xml = (string) $sitemap; // or $sitemap->toXmlString()

// Now do whatever with your xml…
```

The signature for `Sitemap::addUri()` is:

```
Sitemap::addUri(
    string $uri,
    ?\DateTimeInterface $lastMod = null,
    ?string $changeFreq = null,
    ?float $priority = null
) : void;
```

### Multiple sitemaps with an index

[](#multiple-sitemaps-with-an-index)

Adding urls to an index will automatically generate new sitemaps when the max location count is reached for each sitemap. Each sitemap will be named `sitemap-{index}.xml` where `{index}` starts at zero

```
use Netglue\Sitemap\SitemapIndex;
use Netglue\Sitemap\Sitemap;

$index = new SitemapIndex('https://baseurl.host');
// Optionally limit sitemap size (Default is 50k)
$index->setMaxEntriesPerSitemap(10);
// Add a shed load of relative, or absolute URIs
$index->addUri('/someplace');
// ...

// Retrieve the sitemaps and do something with them:
foreach ($index->getSitemaps() as $sitemap) {
    /** @var Sitemap $sitemap */
    $xml = (string) $sitemap;
    $filename = $sitemap->getName(); // i.e 'sitemap-0.xml'
}

// Do something with the Index XML
$indexXml = (string) $index;
```

Writing to Disk
---------------

[](#writing-to-disk)

I figured that if anyone uses this lib, there's a good chance that they may wish to write sitemaps to disk, so it also includes a simple writer class

```
use Netglue\Sitemap\Writer\FileWriter;
use Netglue\Sitemap\SitemapIndex;

$writer = new FileWriter('/path/to/disk/location');
$writer->writeIndex($index);
```

The above will write a Sitemap Index and all the sitemaps found to the given directory. You can provide a filename too instead of the default `sitemap-index.xml`. If you are working with a single sitemap, then this will do the job:

```
use Netglue\Sitemap\Writer\FileWriter;
use Netglue\Sitemap\Sitemap;

$writer = new FileWriter('/path/to/disk/location');
$writer->writeSitemap($sitemap, 'my-sitemap.xml');
```

The filename is optional and defaults to `$sitemap->getName()`

Exceptions
----------

[](#exceptions)

Consistent Exceptions are thrown that all implement `Netglue\Sitemap\Exception\ExceptionInterface`. For example, changefreq, when provided must be valid according to the schema. Priority must be a float between 0 and 1 etc.

License
-------

[](#license)

This lib is MIT Licensed. Do what you like with it, but don't blame anyone if there's a problem

Feedback and Contributions…
---------------------------

[](#feedback-and-contributions)

… are welcomed. Please add tests for any fixes or feature pull requests.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance61

Regular maintenance activity

Popularity33

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% 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 ~1438 days

Total

3

Last Release

180d ago

Major Versions

1.0.0 → 2.0.02020-10-16

2.0.0 → 3.0.02025-11-19

PHP version history (3 changes)1.0.0PHP &gt;=7.1

2.0.0PHP &gt;=7.3

3.0.0PHP ~8.2 || ~8.3 || ~8.4 || ~8.5

### Community

Maintainers

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

---

Top Contributors

[![gsteel](https://avatars.githubusercontent.com/u/2803720?v=4)](https://github.com/gsteel "gsteel (15 commits)")

---

Tags

phpsitemapsitemap-generatorsitemap-xml

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62827.7M220](/packages/scssphp-scssphp)[fivefilters/readability.php

A PHP port of Readability.js

311826.8k5](/packages/fivefilters-readabilityphp)[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[bezhansalleh/filament-panel-switch

Easily Switch between your Filament Panels

159323.5k2](/packages/bezhansalleh-filament-panel-switch)[jane-php/json-schema-runtime

Jane runtime Library

1811.1M13](/packages/jane-php-json-schema-runtime)

PHPackages © 2026

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