A modern, fluent PHP package for building robots.txt files. It powers the
robots.txt on
Dead by Stats.
Why robots-txt
Section titled “Why robots-txt”- Fluent & chainable — every method returns the builder, so a policy reads top to bottom.
- Type-safe crawlers — target bots through
CrawlerEnuminstead of hand-writing user-agent strings. - Validated by design — paths, sitemap URLs, and crawl delays are checked as you build, never at render time.
- Zero runtime dependencies — one small package, nothing to pull in.
Requirements
Section titled “Requirements”- PHP 8.4 or higher
- A code coverage driver (development only)
Installation
Section titled “Installation”composer require fkrzski/robots-txtQuick start
Section titled “Quick start”-
Build a policy:
use Fkrzski\RobotsTxt\RobotsTxt;$robots = (new RobotsTxt())->disallow('/admin')->allow('/public')->crawlDelay(5); -
Render it:
echo $robots->toString();robots.txt User-agent: *Disallow: /adminAllow: /publicCrawl-delay: 5 -
Or write it straight to disk:
$robots->toFile(); // ./robots.txt