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

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

webrium/sitemap
===============

A production-ready PHP library for generating XML sitemaps with support for images, videos, hreflang, gzip compression, and automatic sitemap splitting.

1.0.1(3w ago)011MITPHPPHP ^8.1

Since May 9Pushed 3w agoCompare

[ Source](https://github.com/webrium/sitemap)[ Packagist](https://packagist.org/packages/webrium/sitemap)[ RSS](/packages/webrium-sitemap/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Webrium Sitemap
===============

[](#webrium-sitemap)

A production-ready PHP library for generating standard XML sitemaps with support for images, videos, hreflang (multi-language), gzip compression, and automatic sitemap splitting for large sites.

Requirements
------------

[](#requirements)

- PHP 8.1+
- ext-xmlwriter
- ext-zlib

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

[](#installation)

```
composer require webrium/sitemap
```

Basic Usage
-----------

[](#basic-usage)

```
use Webrium\Sitemap\Sitemap;

$sitemap = new Sitemap('https://example.com');

$sitemap->addUrl('/',      changefreq: Sitemap::FREQ_DAILY,   priority: 1.0); // → https://example.com
$sitemap->addUrl('/about', changefreq: Sitemap::FREQ_MONTHLY, priority: 0.8);
$sitemap->addUrl('/blog',  changefreq: Sitemap::FREQ_DAILY,   priority: 0.9);

echo $sitemap->generate();
```

Adding URLs with Full Options
-----------------------------

[](#adding-urls-with-full-options)

```
use DateTime;
use Webrium\Sitemap\Sitemap;

$sitemap = new Sitemap('https://example.com');

$sitemap->addUrl(
    path:       '/blog/my-post',
    lastmod:    new DateTime('2024-06-01'),
    changefreq: Sitemap::FREQ_WEEKLY,
    priority:   0.7
);
```

Bulk Adding URLs
----------------

[](#bulk-adding-urls)

```
$sitemap->addUrls([
    ['path' => '/page-1', 'priority' => 0.9],
    ['path' => '/page-2', 'changefreq' => Sitemap::FREQ_DAILY],
    ['path' => '/page-3', 'lastmod' => new DateTime('2024-01-01')],
]);
```

Images
------

[](#images)

```
$sitemap->addUrl(
    path:   '/gallery',
    images: [
        [
            'loc'     => 'https://example.com/images/photo.jpg',
            'title'   => 'Photo title',
            'caption' => 'Photo caption',
        ],
    ]
);
```

Videos
------

[](#videos)

```
$sitemap->addUrl(
    path:   '/videos/intro',
    videos: [
        [
            'thumbnail_loc' => 'https://example.com/thumbs/intro.jpg',
            'title'         => 'Introduction',
            'description'   => 'A quick introduction video.',
            'duration'      => 120,
        ],
    ]
);
```

Hreflang (Multi-language)
-------------------------

[](#hreflang-multi-language)

```
$sitemap->addUrl(
    path:       '/about',
    hreflangs:  [
        ['lang' => 'en', 'url' => 'https://example.com/en/about'],
        ['lang' => 'fa', 'url' => 'https://example.com/fa/about'],
        ['lang' => 'x-default', 'url' => 'https://example.com/about'],
    ]
);
```

Saving to File
--------------

[](#saving-to-file)

```
// Plain XML
$sitemap->saveToFile('/var/www/public/sitemap.xml');

// Gzip compressed (use .gz extension)
$sitemap->saveToFile('/var/www/public/sitemap.xml.gz');
```

Large Sites — Automatic Splitting
---------------------------------

[](#large-sites--automatic-splitting)

When your site has more than 50,000 URLs, use `splitAndSave()` to automatically split into multiple files and generate a sitemap index:

```
$sitemap = new Sitemap('https://example.com');

// Add all your URLs (any number)
foreach ($allPages as $page) {
    $sitemap->addUrl($page->path, $page->updatedAt);
}

$indexXml = $sitemap->splitAndSave(
    directory:   '/var/www/public/sitemaps',
    baseFileUrl: 'https://example.com/sitemaps',
    prefix:      'sitemap',
    gzip:        false
);

// Save the index file
file_put_contents('/var/www/public/sitemap-index.xml', $indexXml);
```

This generates `sitemap-1.xml`, `sitemap-2.xml`, ... and a sitemap index pointing to all of them.

Manual Sitemap Index
--------------------

[](#manual-sitemap-index)

```
$indexXml = $sitemap->generateIndex([
    ['loc' => 'https://example.com/sitemaps/sitemap-1.xml', 'lastmod' => new DateTime()],
    ['loc' => 'https://example.com/sitemaps/sitemap-2.xml'],
]);
```

Change Frequency Constants
--------------------------

[](#change-frequency-constants)

ConstantValue`Sitemap::FREQ_ALWAYS`always`Sitemap::FREQ_HOURLY`hourly`Sitemap::FREQ_DAILY`daily`Sitemap::FREQ_WEEKLY`weekly`Sitemap::FREQ_MONTHLY`monthly`Sitemap::FREQ_YEARLY`yearly`Sitemap::FREQ_NEVER`neverLimits
------

[](#limits)

ConstraintValueMax URLs per file50,000Max file size50 MBDuplicate URLsSilently ignoredRunning Tests
-------------

[](#running-tests)

```
composer install
./vendor/bin/phpunit tests/
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~3 days

Total

2

Last Release

27d ago

### Community

Maintainers

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

---

Top Contributors

[![benkhalife](https://avatars.githubusercontent.com/u/31080657?v=4)](https://github.com/benkhalife "benkhalife (7 commits)")[![fphpr](https://avatars.githubusercontent.com/u/47989591?v=4)](https://github.com/fphpr "fphpr (1 commits)")

---

Tags

phpSitemapseoxml-sitemapsitemap-generator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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.5M51](/packages/nystudio107-craft-seomatic)[cyber-duck/silverstripe-seo

A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content

4251.3k](/packages/cyber-duck-silverstripe-seo)[fomvasss/laravel-meta-tags

A package to manage SEO (meta-tags, xml-fields, etc.)

3029.5k](/packages/fomvasss-laravel-meta-tags)[kphoen/sitemap-generator

Provides a way to create/generate a sitemap using Propel, Doctrine, etc.

1688.0k4](/packages/kphoen-sitemap-generator)[calotype/seo

A package containing SEO helpers.

732.6k](/packages/calotype-seo)

PHPackages © 2026

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