tackk/cartographer package in composer) is a tool that helps you to create
sitemap.xml files. But it does not create xml file only. If you have more than 50000 urls (
sitemap.xml limit) - it can automatically generate several sitemap files and connect them with sitemap index file.
Also it uses Flysystem to store generated files so you can save them to Amazon S3 or something like that.
To make sitemap that breaks to several files automatically you need to use
SitemapFactory::createSitemap(Iterator $iterator) method. This allows you to use an iterator class that creates urls on the fly or to use a simple array wrapped with ArrayIterator.
SitemapFactory creates random sitemap file names. This means you need to deal with two problems.
- New sitemap files do not owerwrite old files. You need to remove old sitemaps so you don't accumulate them. Storing all files in one directory allows not to remember file names.
- It's inconvenient to re-generate
robots.txtfile with link to new sitemap every time so it's better to create a persistent url that redirects to latest sitemap file. The simplest way to do it is to create a symlink.