Skip to content

Performance & Workers

PAM Crawl is built to be fast without a browser. It speaks HTTP/2 directly over curl_multi, parses HTML with PHP’s native HTML5 parser, and computes everything about a page lazily: reading only $page->links never pays for Markdown. This page explains the three knobs that matter (concurrency, streaming and worker processes), how persistent PAM workers help, and what the published benchmarks measured.

Two different resources limit a crawl:

  • Network waiting. Most of a page’s time is spent waiting for the server. One PHP process can keep dozens of requests in flight, multiplexed over HTTP/2 connections, so concurrency() is what you tune first.
  • CPU work. Parsing, Markdown conversion and extraction run in PHP on one core per process. When a crawl is CPU-bound (fast or local sites, heavy extraction), workers() spreads that work across processes.
crawl.php
use Pam\Crawl\Crawl;
use Pam\Crawl\Page;
Crawl::urls($urls)
->concurrency(64, perHost: 8)
->each(fn (Page $p) => printf("%d %s\n", $p->status, $p->url));

The defaults are 32 requests in flight and 6 per host. Raising the total helps when you crawl many hosts; the per-host limit protects each site and is usually the one to keep low. See Caching & Politeness for delays and back-off.

Every terminal method except all() and extractAll() streams pages as they complete, so memory stays flat however many URLs you crawl:

Method Returns Memory
stream() / foreach ($crawler as $page) Generator of Page, completion order One page at a time
each(callable $callback) Number of pages; return false to stop early One page at a time
map(callable $fn) Generator of your callback’s results One page at a time
all() list<Page> Every page
get() The first Page One page

map() frees each page’s DOM after your callback runs. If you hold on to pages yourself, call $page->free() once you are done with the parsed document; the raw response stays available.

foreach (Crawl::urls($urls)->stream() as $page) {
$index->add($page->url, $page->content->raw);
$page->free();
}

workers() with map() forks worker processes and hands each one batches of URLs. Fetching, parsing, Markdown and extraction then scale with CPU cores:

crawl.php
$results = Crawl::urls($tenThousandUrls)
->workers(8) // processes; workers() with no argument = one per CPU core
->concurrency(16) // requests in flight in each worker
->map(fn (Page $p): array => [
'url' => $p->url,
'title' => $p->meta->title,
'words' => $p->wordCount,
]);
foreach ($results as $row) {
// rows stream back as workers finish them
}

Keep these rules in mind:

  • Return plain data. Your callback runs inside a worker, and its return value is serialized back to the parent. Return arrays, scalars or small objects, not the Page.
  • Concurrency is per worker. workers(4)->concurrency(2, perHost: 2) keeps at most 8 requests in flight in total. Size both so the total per host stays polite.
  • Batches are handed out on demand. The third argument of map() sets the batch size (default 64); a slow batch never stalls the others. With few URLs, lower it so every worker gets work: ->map($fn, batch: 5).
  • Deep crawls stay inline. Crawl::site() needs one shared frontier, so it ignores workers. Seed URLs first (see Deep Crawling & Seeding) and pass them to Crawl::urls() to parallelize.
  • pcntl is required. Without the pcntl extension (Windows, PHP-FPM) or with one worker, map() runs inline in the current process. Pam\Crawl\Parallel\Pool::supported() tells you which mode you get. The PAM runtime includes pcntl.

When PAM Crawl runs inside a long-lived PAM worker (the HTTP API, a queue worker or your own pam start server), state that is expensive to rebuild survives between requests:

  • HTTP/2 connections stay warm, so later requests to the same host skip TCP and TLS setup.
  • robots.txt rules are cached per user agent for 24 hours.
  • SQLite cache handles are opened once per worker.
  • Browser tabs opened with tab() stay alive (with the browser plugin).

The library itself runs on plain PHP 8.5 too; on PAM you additionally get these persistent workers and pam start clustering.

The package’s benchmark crawled 460 real pages (books.toscrape.com, docs.python.org and quotes.toscrape.com) mirrored to a local nginx, so the network is not the bottleneck. Every page went through Markdown, fit Markdown, links, images and metadata. Crawl4AI 0.9.6 used its PruningContentFilter, and the whole process tree was measured, browsers included. Machine: Linux, Core Ultra 9 185H, PAM 2.2.27 (PHP 8.5).

Tool Pages/s Wall time Peak RAM CPU time
PAM Crawl, 8 workers (->workers(8)->map()) 448 1.0 s 418 MB 4.1 s
PAM Crawl, 1 process, concurrency 16 141 to 152 3.0 s 94 MB 3.1 s
PAM Crawl on plain PHP (no PAM) 144 3.2 s 93 MB 3.2 s
Crawl4AI, AsyncHTTPCrawlerStrategy, concurrency 16 7.9 58 s 525 MB 60.8 s
Crawl4AI, default browser strategy, concurrency 16 6.3 71 s 3,774 MB 153 s

On one core, that is about 18 times the throughput of Crawl4AI’s HTTP mode and about 22 times its browser mode, with about 20 times less CPU per page. These numbers describe one corpus on one machine; measure your own workload before sizing production.

To reproduce them, clone the repository and follow bench/README.md: build the corpus with bench/mirror_corpus.php, serve it locally, and run bench/pam_bench.php, bench/pam_parallel_bench.php and bench/c4a_bench.py under bench/monitor.py. Raw results are in bench/results-2026-12-02.jsonl.


This product includes software developed by UncleCode (https://x.com/unclecode) as part of the Crawl4AI project (https://github.com/unclecode/crawl4ai).