{"id":31853578,"url":"https://github.com/o/sitemap-php","last_synced_at":"2025-10-12T13:31:44.093Z","repository":{"id":1315576,"uuid":"1260406","full_name":"o/sitemap-php","owner":"o","description":"Library for generating Google sitemap XML files","archived":false,"fork":false,"pushed_at":"2020-10-12T09:23:54.000Z","size":20,"stargazers_count":302,"open_issues_count":17,"forks_count":176,"subscribers_count":27,"default_branch":"develop","last_synced_at":"2025-09-21T11:43:35.407Z","etag":null,"topics":["generating-sitemaps","google-sitemap","php","sitemap","sitemap-files","sitemap-php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/o.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-01-16T13:41:06.000Z","updated_at":"2025-08-13T15:20:32.000Z","dependencies_parsed_at":"2022-07-06T21:24:19.540Z","dependency_job_id":null,"html_url":"https://github.com/o/sitemap-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/o/sitemap-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o%2Fsitemap-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o%2Fsitemap-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o%2Fsitemap-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o%2Fsitemap-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o","download_url":"https://codeload.github.com/o/sitemap-php/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o%2Fsitemap-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011443,"owners_count":26084947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generating-sitemaps","google-sitemap","php","sitemap","sitemap-files","sitemap-php"],"created_at":"2025-10-12T13:30:19.892Z","updated_at":"2025-10-12T13:31:44.084Z","avatar_url":"https://github.com/o.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"**For the 90's people, i'm keeping this repository as 5.2 compatible. If you need PSR-0 and Composer compatible version, [here is a fork that maintained by Evert Pot](https://github.com/evert/sitemap-php).**\n\nWhat is sitemap-php ?\n----------\n\nFast and lightweight class for generating Google sitemap XML files and index of sitemap files. Written on PHP and uses XMLWriter extension (wrapper for libxml xmlWriter API) for creating XML files. XMLWriter extension is enabled by default in PHP 5 \u003e= 5.1.2. If you having more than 50000 url, it splits items to seperated files. _(In benchmarks, 1.000.000 url was generating in 8 seconds)_\n\nHow to use\n----------\n\nInclude Sitemap.php file to your PHP document and call Sitemap class with your base domain.\n\n\tinclude 'Sitemap.php';\n\t$sitemap = new Sitemap('http://example.com');\t\n\nNow, we need to define path for saving XML files. This can be relative like `xmls` or absolute `/path/to/your/folder` and *must be a writable folder*. In default it uses same folder with your script.\n\n\t$sitemap-\u003esetPath('xmls/');\n\nGenerated XML file names defaulted to `sitemap-*.xml`, you can customize prefix of filenames with `setFilename` method.\n\n\t$sitemap-\u003esetFilename('customsitemap');\n\n\t\nWe'll add sitemap url's with `addItem` method. In this method, only first parameter (location) is required.\n\n\t$sitemap-\u003eaddItem('/', '1.0', 'daily', 'Today');\n\t$sitemap-\u003eaddItem('/about', '0.8', 'monthly', 'Jun 25');\n\t$sitemap-\u003eaddItem('/contact', '0.6', 'yearly', '14-12-2009');\n\t$sitemap-\u003eaddItem('/otherpage');\n\nw/ method chaining.\n\n\t$sitemap-\u003eaddItem('/projects', '0.8')-\u003eaddItem('/somepage')-\u003eaddItem('/hiddenpage', '0.4', 'yearly', '01-01-2011')-\u003eaddItem('/rss');\n\nfrom a sql result, or whatever.\n\n\t$query = Doctrine_Query::create()\n\t\t\t\t\t-\u003eselect('p.created_at, p.slug')\n\t\t\t\t\t-\u003efrom('Posts p')\n\t\t\t\t\t-\u003eorderBy('p.id DESC')\n\t\t\t\t\t-\u003euseResultCache(true);\n\t$posts =  $query-\u003efetchArray(array(), Doctrine_Core::HYDRATE_ARRAY);\n    foreach ($posts as $post) {\n        $sitemap-\u003eaddItem('/post/' . $post['slug'], '0.6', 'weekly', $post['created_at']);\n    }\n\nIf you need to change domain for sitemap instance, you can override it via `setDomain` method.\n\n\t$sitemap-\u003esetDomain('http://blog.example.com');\n\t\nFinally we create index for sitemap files. **This method also closes tags of latest generated xml file.**\n\n\t$sitemap-\u003ecreateSitemapIndex('http://example.com/sitemap/', 'Today');\n\t\nWhen you run your script, it generates and saves XML files to given path.\n\nsitemap-0.xml\n\n\t\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n\t \u003curl\u003e\n\t  \u003cloc\u003ehttp://example.com/\u003c/loc\u003e\n\t  \u003cpriority\u003e1.0\u003c/priority\u003e\n\t  \u003cchangefreq\u003edaily\u003c/changefreq\u003e\n\t  \u003clastmod\u003e2011-04-07\u003c/lastmod\u003e\n\t \u003c/url\u003e\n\t \u003curl\u003e\n\t  \u003cloc\u003ehttp://example.com/about\u003c/loc\u003e\n\t  \u003cpriority\u003e0.8\u003c/priority\u003e\n\t  \u003cchangefreq\u003emonthly\u003c/changefreq\u003e\n\t  \u003clastmod\u003e2011-06-25\u003c/lastmod\u003e\n\t \u003c/url\u003e\n\t \u003curl\u003e\n\t  \u003cloc\u003ehttp://example.com/contact\u003c/loc\u003e\n\t  \u003cpriority\u003e0.6\u003c/priority\u003e\n\t  \u003cchangefreq\u003eyearly\u003c/changefreq\u003e\n\t  \u003clastmod\u003e2009-12-14\u003c/lastmod\u003e\n\t \u003c/url\u003e\n\t \u003curl\u003e\n\t  \u003cloc\u003ehttp://example.com/otherpage\u003c/loc\u003e\n\t  \u003cpriority\u003e0.5\u003c/priority\u003e\n\t \u003c/url\u003e\n\t\u003c/urlset\u003e\n\t\nsitemap-index.xml\n\n\t\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\u003csitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n\t \u003csitemap\u003e\n\t  \u003cloc\u003ehttp://example.com/sitemap/sitemap-0.xml\u003c/loc\u003e\n\t  \u003clastmod\u003e2011-04-07\u003c/lastmod\u003e\n\t \u003c/sitemap\u003e\n\t\u003c/sitemapindex\u003e\n\t\nYou need to submit sitemap-index.xml to Google Sitemaps.\n\n**Please note that, generating sitemaps not overrides any previous generated sitemap file. You need to delete old files before the operation.**\n\n\t$ rm -rv sitemap-*\n\nFor the truncating a file with php, use the following snippet:\n\n\t$handle = fopen(\"/path/to/sitemap/file.xml\", \"w\");\n\tfclose($handle);\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo%2Fsitemap-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo%2Fsitemap-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo%2Fsitemap-php/lists"}