savanasoft/seo-sitemap
Composer 安装命令:
composer require savanasoft/seo-sitemap
包简介
A powerful, flexible PHP library for generating SEO sitemaps — XML, Image, Video, News and Sitemap Index.
README 文档
README
A powerful, flexible PHP 8.1+ library for generating SEO-optimized XML sitemaps — supporting standard URLs, Images, Videos, News and Sitemap Index files, all compliant with sitemaps.org and Google's sitemap extensions.
✨ Features
- ✅ Standard Sitemap —
<loc>,<lastmod>,<changefreq>,<priority> - 🖼️ Image Sitemap Extension — Google image sitemap support
- 🎬 Video Sitemap Extension — Google video sitemap support
- 📰 News Sitemap Extension — Google News sitemap support
- 📂 Sitemap Index — Split large sites into multiple indexed sitemaps
- 🗜️ Gzip Support — Write compressed
.xml.gzsitemaps - 🛡️ Validation — Enforces 50,000 URL and 50MB limits automatically
- 🔒 Immutable Value Objects — Safe, fluent, side-effect-free API
- 🧪 100% Tested — PHPUnit test suite included
📦 Installation
composer require devbg/seo-sitemap
Requirements: PHP 8.1+, ext-dom, ext-libxml
🚀 Quick Start
Simple sitemap
use DevBG\SeoSitemap\SitemapUrl; use DevBG\SeoSitemap\Generators\SitemapGenerator; use DevBG\SeoSitemap\Renderers\FileWriter; $generator = new SitemapGenerator(prettyPrint: true); $generator->addUrl(new SitemapUrl( loc: 'https://example.com/', lastmod: new DateTimeImmutable(), changefreq: SitemapUrl::CHANGE_FREQ_DAILY, priority: 1.0, )); $generator->addUrl(new SitemapUrl( loc: 'https://example.com/about', changefreq: SitemapUrl::CHANGE_FREQ_MONTHLY, priority: 0.5, )); // Get XML as string echo $generator->generate(); // Or write to file $generator->writeTo(new FileWriter(), '/var/www/public/sitemap.xml');
With Image extension
use DevBG\SeoSitemap\ImageEntry; $url = (new SitemapUrl('https://example.com/products/laptop')) ->addImage(new ImageEntry( loc: 'https://example.com/images/laptop-front.jpg', caption: 'Laptop front view', title: 'Premium Laptop', license: 'https://creativecommons.org/licenses/by/4.0/', geoLocation: 'Sofia, Bulgaria', )) ->addImage(new ImageEntry( loc: 'https://example.com/images/laptop-side.jpg', caption: 'Laptop side view', )); $generator->addUrl($url);
With News extension
use DevBG\SeoSitemap\NewsEntry; $url = (new SitemapUrl('https://example.com/news/ai-revolution-2024')) ->withNews(new NewsEntry( publicationName: 'Example News', publicationLanguage: 'en', publicationDate: new DateTimeImmutable('2024-11-01T09:00:00Z'), title: 'The AI Revolution Is Here', keywords: 'AI, machine learning, LLM, future', genres: 'PressRelease, Blog', )); $generator->addUrl($url);
With Video extension
use DevBG\SeoSitemap\VideoEntry; $url = (new SitemapUrl('https://example.com/videos/php-tutorial')) ->addVideo(new VideoEntry( thumbnailLoc: 'https://example.com/thumbnails/php-tutorial.jpg', title: 'PHP 8.3 for Beginners', description: 'A complete introduction to modern PHP development.', contentLoc: 'https://example.com/videos/php-tutorial.mp4', duration: 3600, rating: 4.8, viewCount: 15000, publicationDate: new DateTimeImmutable('2024-01-10'), familyFriendly: true, )); $generator->addUrl($url);
📂 Sitemap Index (Large Sites)
For sites with more than 50,000 URLs, use multiple sitemaps and an index:
use DevBG\SeoSitemap\Generators\SitemapIndexGenerator; use DevBG\SeoSitemap\Renderers\FileWriter; $index = new SitemapIndexGenerator(prettyPrint: true); $index->addSitemap('https://example.com/sitemap-pages.xml', new DateTimeImmutable()); $index->addSitemap('https://example.com/sitemap-products.xml', new DateTimeImmutable()); $index->addSitemap('https://example.com/sitemap-blog.xml', new DateTimeImmutable()); $index->writeTo(new FileWriter(), '/var/www/public/sitemap.xml');
🧙 SitemapManager (Recommended for large projects)
The SitemapManager handles everything automatically — writes individual sitemap files and generates the index:
use DevBG\SeoSitemap\SitemapManager; use DevBG\SeoSitemap\SitemapUrl; $manager = new SitemapManager( baseUrl: 'https://example.com', outputPath: '/var/www/public', prettyPrint: true, ); // Add pages to named sitemaps $manager->sitemap('pages') ->addUrl(new SitemapUrl('https://example.com/', priority: 1.0)) ->addUrl(new SitemapUrl('https://example.com/about', priority: 0.8)); $manager->sitemap('blog') ->addUrl(new SitemapUrl('https://example.com/blog/post-1')) ->addUrl(new SitemapUrl('https://example.com/blog/post-2')); // Writes: // /var/www/public/sitemap-pages.xml // /var/www/public/sitemap-blog.xml // /var/www/public/sitemap.xml ← index $manager->write();
🗜️ Gzip Compression
use DevBG\SeoSitemap\Renderers\GzipWriter; $generator->writeTo(new GzipWriter(), '/var/www/public/sitemap.xml.gz');
🔁 Change Frequency Constants
SitemapUrl::CHANGE_FREQ_ALWAYS // always SitemapUrl::CHANGE_FREQ_HOURLY // hourly SitemapUrl::CHANGE_FREQ_DAILY // daily SitemapUrl::CHANGE_FREQ_WEEKLY // weekly SitemapUrl::CHANGE_FREQ_MONTHLY // monthly SitemapUrl::CHANGE_FREQ_YEARLY // yearly SitemapUrl::CHANGE_FREQ_NEVER // never
🧪 Testing
composer test
📊 Limits (enforced automatically)
| Limit | Value |
|---|---|
| URLs per sitemap | 50,000 |
| Max file size | 50 MB |
| Solution for large sites | SitemapIndexGenerator or SitemapManager |
🚀 Professional SEO & Web Design Services
This open-source project is maintained by our team. If you need a custom solution, a high-converting website, or an expert SEO strategy, feel free to reach out to us:
- [Savana Soft] – High-end Ecommerce Web Design and performance-driven SEO Services.
- Expert SEO Audit – Get a comprehensive analysis of your website’s visibility.
- Custom Web Development – Scalable PHP and JavaScript solutions tailored to your business needs.
Let's build something great together: 👉 https://savana-soft.com
📄 License
MIT — see LICENSE file.
savanasoft/seo-sitemap 适用场景与选型建议
savanasoft/seo-sitemap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Sitemap」 「seo」 「xml-sitemap」 「sitemap-index」 「image-sitemap」 「video-sitemap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 savanasoft/seo-sitemap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 savanasoft/seo-sitemap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 savanasoft/seo-sitemap 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content
Symfony sitemap generator
PHP Simple Sitemap Generator
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content (forked from Cyber-Duck/Silverstripe-SEO)
Interfaces for web resource models and services to retrieve and create them
Help to manage meta data on Laravel Eloquent model
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-22