Download the PHP package tonsoo/php-crawler without Composer
On this page you can find all versions of the php package tonsoo/php-crawler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-crawler
Sitemap Generator Crawler
A small, dependency-light PHP crawler that walks a site and generates XML sitemaps. It follows links, respects meta robots directives, and ships with a sitemap extension that can write a single sitemap or rotate into multiple files with an index.
Requirements
- PHP 8.4+
- Extensions:
ext-dom,ext-curl,ext-xmlwriter
Installation
Quick Start
This will crawl https://example.com, write sitemap.xml (or sitemap-2.xml, sitemap-3.xml, etc.), and produce a sitemap-index.xml once multiple sitemap files are created.
Crawler Configuration
The crawler is configured via a fluent API on Crawler:
What these options do
displayCrawls(true): toggles crawl logging (currently not used by the built-in logger).displayMemoryInfo(true): toggles memory logging (currently not used by the built-in logger).respectNoIndex(true): honors<meta name="robots" content="noindex">(default:true).respectNoFollow(true): honors<meta name="robots" content="nofollow">(default:true).respectCanonical(true): uses the canonical URL for link resolution (default:true).preserveScheme(true): stays on the same scheme (httpvshttps) (default:true).preserveHost(true): stays on the same host (default:true).maxPages(5000): stops after a page limit (default:null= unlimited).
Sitemap Generation
Single sitemap
Rotating sitemap + index
Notes:
RotatingSitemapWriterrequires the directory to already exist.- The index file is written only when more than one sitemap file is created.
- The index stores the sitemap filenames (relative paths), not absolute URLs.
Events
You can subscribe to crawler events to observe or extend behavior:
Custom HTTP Client, Logger, and Analyzer
You can plug in your own implementations:
Defaults:
- HTTP client:
CurlHttpClient(follows redirects, 4s connect/total timeout, custom UA string). - Logger:
ConsoleLogger(timestamps to stdout). - Analyzer:
DomDocumentPageAnalyzer(DOM + XPath).
Interfaces to implement:
HttpClientInterface::fetch(string $url): ResultLoggerInterface::log(string $message): voidPageAnalyzerInterface::analyze(Result $result, bool $respectNoIndex, bool $respectNoFollow): PageAnalysis
Error Handling
If maxPages is set and the crawler reaches the limit, it throws LimitExceededException after finishing the crawl loop:
Crawling Behavior
The crawler only processes pages that return an HTML body with a text/html content type. If a page has no HTML body or a non-HTML content type, it is skipped and the corresponding event is emitted.
The crawler collects links from <a href="..."> elements and normalizes them. It will:
- Resolve relative URLs against the current page
- Drop fragments (the
#...part) - Ignore non-HTTP(S) schemes
- Optionally restrict links by host and scheme
- Optionally respect
noindex/nofollowmeta tags (from<meta name="robots">) - Use canonical URLs when enabled
This crawler does not parse robots.txt.
Example Script
See examples/crawler.php for a full working example.
All versions of php-crawler with dependencies
ext-dom Version *
nesbot/carbon Version ^3.11
league/uri Version ^7.8
ext-curl Version *
ext-xmlwriter Version *