承接 kri55h/php-sitemapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kri55h/php-sitemapper

Composer 安装命令:

composer require kri55h/php-sitemapper

包简介

php-sitemapper: A lightweight and powerful PHP library for generating dynamic XML sitemaps effortlessly. Designed to help developers enhance their website's SEO by creating search-engine-friendly sitemaps, this tool is perfect for small and large-scale projects alike.

README 文档

README

SiteMapper is a lightweight, chainable PHP library to generate SEO-friendly XML sitemaps dynamically.
Designed for modern PHP projects and frameworks (Laravel, Codeigniter, Symfony, plain PHP).

Features

  • Fluent API: addUrl(...)->save() for concise, readable code.
  • Add per-URL metadata: priority, lastmod and changefreq.
  • generateXml() returns an XML string ready to return from controllers.
  • outputXml() sends correct headers and echoes XML directly.
  • saveToFile() writes sitemap XML to disk.
  • Minimal dependencies — requires only PHP and SimpleXML.

Requirements

  • PHP 7.4 or newer
  • ext-simplexml enabled

Installation

Install via Composer:

composer require kri55h/php-sitemapper

Then autoload:

require 'vendor/autoload.php';

use Kri55h\SiteMapper;

Quick Example (recommended)

<?php
require 'vendor/autoload.php';

use Kri55h\SiteMapper;

$map = new SiteMapper();

// Add and save entries (pass full URLs)
$map->addUrl('https://example.com/about', 0.8, '2025-08-09', 'daily')->save()
    ->addUrl('https://example.com/contact', 0.5, '2025-08-09', 'weekly')->save();

// Return XML from a controller or script
header('Content-Type: application/xml; charset=UTF-8');
echo $map->generateXml();

Important: addUrl() stages a URL in memory. Call save() to commit the staged entry into the sitemap list — otherwise it will not appear in generateXml().

Full Example (all functions / backwards-compatible style)

<?php
require 'vendor/autoload.php';

use Kri55h\SiteMapper;

$map = new SiteMapper();

// Staged style: call setters, then save()
$map->addUrl('https://example.com/')
    ->setPriority(1.0)
    ->setLastModified('2025-08-09')
    ->setChangeFrequency('daily')
    ->save();

// Another entry, using positional args
$map->addUrl('https://example.com/about', 0.8, '2025-08-09', 'weekly')->save();

// Save sitemap to disk
$map->saveToFile(__DIR__ . '/public/sitemap.xml');

// Or output directly (sets header + echoes XML)
$map->outputXml();

Public API Reference

  • addUrl(string $location, ?float $priority = null, ?string $last_modified = null, ?string $change_frequency = null): self Adds a staged URL entry. Pass a full URL (https://example.com/page). Returns $this for chaining.

  • setPriority(float $priority): self Set priority (0.0 — 1.0) for the currently staged entry. Chainable.

  • setLastModified(string $last_modified): self Set the last modified date (YYYY-MM-DD) for the currently staged entry. Chainable.

  • setChangeFrequency(string $change_frequency): self Set change frequency (always|hourly|daily|weekly|monthly|yearly|never). Chainable.

  • save(): self Commit the currently staged entry into the sitemap list. Throws RuntimeException if no loc was staged. Chainable.

  • generateXml(): string Generate and return the sitemap XML string. Use this to return XML from controller routes.

  • outputXml(): void Send Content-Type: application/xml; charset=UTF-8 and echo the generated XML. Convenience helper for quick endpoints.

  • saveToFile(string $filePath): void Write the generated sitemap XML to the given file path.

Migration notes (from previous versions that had addBaseUrl())

If you upgraded from a version that supported addBaseUrl() and relative paths:

  • Before (old):
$map->addBaseUrl('https://example.com');
$map->addUrl('/about');
echo $map->generateXml();
  • Now (new):
$map->addUrl('https://example.com/about')->save();
echo $map->generateXml();

Why: The library no longer maintains global base URL state. This makes the API explicit and safer for mixed-domain usages.

Best practices

  • Always call save() after addUrl() (or use positional arguments with addUrl(...)->save()).

  • Use generateXml() to return XML from controllers (so the framework can manage responses).

  • Use outputXml() only for simple scripts or endpoints where you want the library to send headers.

  • For bulk imports, add entries in a loop and call save() per entry, or implement your own batching helper.

License

This project is licensed under the MIT License.

Author

Krish Siddhapura — siddhapurakrish007@gmail.comhttps://github.com/KRI55H

Keywords (for SEO)

PHP sitemap generator, XML sitemap, SEO sitemap PHP, SiteMapper, sitemap generator, Laravel sitemap generator, dynamic sitemap, Laravel dynamic sitemap generator.

kri55h/php-sitemapper 适用场景与选型建议

kri55h/php-sitemapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「PHP sitemap generator」 「Dynamic XML sitemap」 「SEO-friendly sitemap library」 「Generate sitemaps in PHP」 「Lightweight PHP sitemap tool」 「Laravel sitemap generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kri55h/php-sitemapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kri55h/php-sitemapper 我们能提供哪些服务?
定制开发 / 二次开发

基于 kri55h/php-sitemapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-22