A modern, fluent PHP package for building robots.txt files. It powers the robots.txt on Dead by Stats.

  • Fluent & chainable — every method returns the builder, so a policy reads top to bottom.
  • Type-safe crawlers — target bots through CrawlerEnum instead 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.
  • PHP 8.4 or higher
  • A code coverage driver (development only)
Terminal window
composer require fkrzski/robots-txt
  1. Build a policy:

    use Fkrzski\RobotsTxt\RobotsTxt;
    $robots = (new RobotsTxt())
    ->disallow('/admin')
    ->allow('/public')
    ->crawlDelay(5);
  2. Render it:

    echo $robots->toString();
    robots.txt
    User-agent: *
    Disallow: /admin
    Allow: /public
    Crawl-delay: 5
  3. Or write it straight to disk:

    $robots->toFile(); // ./robots.txt