PAM Crawl
PAM Crawl (pushinbr/pam-crawl) is a web crawler and scraper for PHP. Give it a URL, a list
of URLs or a whole site, and it hands you back clean Markdown, page metadata, links, images,
tables and typed PHP objects, ready to index, store or send to an LLM.
It is a PHP re-implementation of the ideas in Crawl4AI,
with a different engine underneath. Instead of opening a browser for every page, PAM Crawl speaks
HTTP/2 directly (many requests multiplexed over few connections), parses with PHP’s native HTML5
parser and computes everything lazily: reading only $page->links never pays for Markdown. When a
page truly needs JavaScript, the optional browser plugin renders it.
You would reach for PAM Crawl when you need to:
- feed documentation, articles or product pages into a RAG index or an LLM prompt;
- scrape structured data (prices, listings, quotes) into your own PHP classes;
- crawl a documentation section or a whole site politely, with robots.txt and per-host limits;
- monitor pages for changes, map a domain, or discover URLs from sitemaps.
Installation
Section titled “Installation”PAM Crawl requires PHP 8.5 with ext-curl, ext-dom and ext-mbstring, which the PAM runtime
already ships. ext-pdo_sqlite is needed only for the HTTP cache and change monitoring.
If you have not installed PAM yet, follow the installation guide, then:
mkdir my-crawler && cd my-crawlerpam composer init --no-interactionpam composer require pushinbr/pam-crawl:^0.1The library, the CLI and the HTTP API also run on any PHP 8.5 (CLI, PHP-FPM, Laravel, Symfony, cron):
composer require pushinbr/pam-crawl:^0.1 # without PAMPAM adds persistent workers, warm HTTP/2 connections and caches that live across requests, which is what makes PAM Crawl fastest under the PAM runtime.
Your first crawl
Section titled “Your first crawl”Create a script that fetches one page and prints its main content as Markdown:
<?php
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
use Pam\Crawl\Crawl;
$page = Crawl::url('https://example.com/')->get();
echo $page->status, ' ', $page->meta->title, "\n"; // 200 Example Domainecho $page->content->raw, "\n"; // main content only, as MarkdownRun it with PAM:
pam crawl.php$page->content is the page’s main content with navigation, footers and other boilerplate
removed (Crawl4AI calls this “fit Markdown”). $page->markdown is the whole page. Both are
covered in Markdown & Content.
Many URLs at once
Section titled “Many URLs at once”Crawl::urls() accepts any iterable of URLs and fetches them concurrently. Pages are yielded
as they complete, not in input order:
use Pam\Crawl\Crawl;use Pam\Crawl\Page;
$count = Crawl::urls(['https://example.com/', 'https://example.org/']) ->concurrency(2) ->each(function (Page $page): void { printf("%d %s (%d words)\n", $page->status, $page->url, $page->wordCount); });each() returns the number of pages it visited. Return false from the callback to stop early.
A whole site
Section titled “A whole site”Crawl::site() starts a deep crawl. It stays on the seed’s host, follows links breadth-first,
respects robots.txt and skips static assets and “nonsense” URLs (login, cart, search…) by default:
use Pam\Crawl\Crawl;use Pam\Crawl\Page;
Crawl::site('https://docs.example.com/') ->only('/guide/*') ->depth(2) ->limit(50) ->each(fn (Page $page) => file_put_contents( 'out/'.md5($page->url).'.md', $page->content->raw, ));See Deep Crawling & Seeding for strategies, filters and scorers.
HTML you already have
Section titled “HTML you already have”Crawl::html() runs the same pipeline over a string, which is handy for tests and for HTML
you fetched some other way:
$page = Crawl::html('<article><h1>Hi</h1><p>Hello <a href=/about>world</a></p></article>', 'https://acme.example.com/')->get();
echo $page->markdown->raw;// # Hi//// Hello [world](https://acme.example.com/about)Running a crawl
Section titled “Running a crawl”Every Crawl:: factory returns an immutable Pam\Crawl\Crawler. Each configuration method
returns a new crawler, so you can keep a base configuration and derive variants from it. Nothing
is fetched until you call one of the terminal methods:
| Method | Returns |
|---|---|
get() |
The first Page (for a single URL). |
stream() |
A generator of Page objects in completion order. A Crawler is also iterable directly. |
each(callable $callback) |
Calls the callback for every page; returns the page count. Return false to stop. |
all() |
A list of every Page. Prefer stream() or each() for large crawls. |
map(callable $fn, ?int $workers = null) |
A generator of the callback’s return values, optionally across worker processes. |
markdown(bool $fit = false) |
The Markdown of every page, joined. |
extract(string $class) / extractAll(string $class) |
Typed objects, see Extraction. |
Configuration
Section titled “Configuration”Configuration lives on the crawler itself. The most common options and their defaults:
| Method | Default | What it does |
|---|---|---|
concurrency(int $total, ?int $perHost = null) |
32 total, 6 per host | Requests in flight. |
perHost(int $connections) |
6 | Connections per host. |
delay(float $seconds) |
0 | Minimum seconds between requests to the same host. |
jitter(float $seconds) |
0 | Random extra delay per request to the same host. |
timeout(float $seconds, ?float $connect = null) |
20 s, 10 s connect | Request timeouts. |
retries(int $retries) |
2 | Retries for failed requests. |
maxBytes(int $bytes) |
10 MB | Maximum response body size. |
respectRobots(bool $respect = true) |
off for url()/urls(), on for site() |
Obey robots.txt (RFC 9309). |
userAgent(string $ua) / randomUserAgent(?string $device = null, int $rotate = 1) |
A desktop Chrome UA | Identity sent with each request. |
headers(array $headers) / header(string $name, string $value) |
none | Extra request headers. |
cookies(array $cookies) / session(?string $cookieJarFile = null) |
none | Static cookies, or a cookie jar shared by all requests. |
proxy(string ...$proxies) |
none | One proxy, or several rotated round-robin. |
cache(string|bool $path = true, ?float $ttl = null) |
off | SQLite HTTP cache with revalidation. |
anyContentType() |
HTML, XML, JSON and text only | Accept any content type. |
downloads(string $directory, int $maxBytes = 512 MB) |
off | Stream non-text responses (PDFs, archives) to disk. |
Content options (selector(), target(), exclude(), excludeTags(), withoutImages()…) are
covered in Markdown & Content. Caching and politeness are covered in
depth in Caching & Politeness.
use Pam\Crawl\Crawl;
$crawler = Crawl::urls($urls) ->concurrency(16, perHost: 2) ->delay(0.5) ->respectRobots() ->userAgent('AcmeBot/1.0 (+https://acme.example.com/bot)') ->cache(); // ./.cache/pam-crawl.sqliteThe page object
Section titled “The page object”Every result is a Pam\Crawl\Page. Everything derived from the HTML is computed on first access
and then memoized:
| Property | Description |
|---|---|
ok, status, error, blocked |
Whether the fetch succeeded, the HTTP status, the error message and bot-wall detection. |
url, finalUrl, depth, parent |
The requested URL, the URL after redirects, and the crawl depth and parent page. |
html, cleanedHtml, text, wordCount |
Raw HTML, cleaned HTML, plain visible text and its word count. |
markdown, content |
Full-page and main-content Markdown. |
meta, links, images, videos, audios, tables, jsonLd |
Page data. |
json, feed, pdf |
Decoded JSON bodies, parsed RSS/Atom feeds and downloaded PDFs. |
embedded, isShell |
Hydration data from JavaScript apps and app-shell detection. |
fromCache, elapsed |
Whether the response came from the cache, and the request time in seconds. |
$page->toArray() and json_encode($page) give you a serializable summary. In long crawls, call
$page->free() once you are done with a page to release its DOM and derived caches.
Responsible use
Section titled “Responsible use”In this guide
Section titled “In this guide”PAM Crawl is open source under the Apache License 2.0. This product includes software developed by UncleCode (https://x.com/unclecode) as part of the Crawl4AI project (https://github.com/unclecode/crawl4ai). PAM Crawl is not affiliated with or endorsed by the Crawl4AI project.