Skip to content

Repository files navigation

PHP Screenshot Benchmarks

Companion examples and benchmarks for the Screenshot Scout article How to Take Website Screenshots in PHP (Benchmarked).

The project has two parts:

  • copy-pasteable examples for Spatie Browsershot, php-webdriver with Selenium / ChromeDriver, chrome-php/chrome, and Screenshot Scout;
  • reproducible benchmark runners for performance and reliability screenshots.

Setup

Install PHP 8.2 or newer, Composer, Node.js 22.12 or newer, and npm.

composer install
npm ci
npm run setup-browsers

The browser setup command downloads the current stable Chrome for Testing and matching ChromeDriver into .cache/browsers/ and writes .cache/browsers/paths.json. Local benchmark tools use those project-local binaries rather than whatever Chrome happens to be installed on the machine.

Local Chromium tools use shared automation/stability launch flags to avoid first-run setup and suppress successful Chrome/ChromeDriver console noise. Failed captures still print error details.

Screenshot Scout examples and benchmarks require an access key.

On Windows PowerShell:

$env:SCREENSHOT_SCOUT_ACCESS_KEY = "your_access_key"

On macOS/Linux:

export SCREENSHOT_SCOUT_ACCESS_KEY=your_access_key

Examples

Each example is standalone and designed to appear verbatim in the article.

php examples/browsershot/screenshot.php
php examples/php_webdriver/full_page_screenshot.php
php examples/chrome_php/element_screenshot.php
php examples/screenshot_scout/screenshot.php

Benchmarks

php benchmark/run.php

The combined benchmark command creates one timestamped run folder and runs both performance measurements and reliability screenshot capture into it.

Performance measurements use cold starts: launch, capture, close. The runner records wall time, peak local RAM, and local CPU-seconds by sampling the worker process tree.

By default, performance runs benchmark normal viewport screenshots. Optional --performance-kind full_page and --performance-kind selector modes are available for exploratory measurements; selector mode uses selector from manifests/performance.toml.

Screenshot Scout rendering happens on Screenshot Scout infrastructure, so local CPU/RAM numbers represent only client-side request handling. Wall time still measures how long the screenshot request takes from start to finish.

The reliability runner captures each configured page once per tool and saves screenshots under runs/<timestamp>/screenshots/reliability/. It does not grade pass/fail.

For the bot_protection reliability category, php-webdriver uses sapistudio/seleniumstealth plus matching Selenium ChromeOptions. The other local browser tools use their default automation behavior for that category.

Reliability runs also write runs/<timestamp>/results/reliability_raw.csv for manual grading. After filling the result column, run:

php benchmark/reliability/summarize.php runs/<timestamp>/results/reliability_raw.csv

The benchmark can also run in Docker:

docker build -t php-screenshot-benchmarks .
docker run --rm -it --shm-size=2g -e SCREENSHOT_SCOUT_ACCESS_KEY="$SCREENSHOT_SCOUT_ACCESS_KEY" -v "$PWD/runs:/app/runs" php-screenshot-benchmarks
php benchmark/run.php

uBlock Origin Lite

Local browser-library ad and cookie-banner cleanup benchmarks use uBlock Origin Lite. The benchmark downloads a pinned official uBOL release into .cache/ on first use and loads it as an unpacked extension. The extension is not committed to this repository.

Outputs

Each run writes:

runs/<timestamp>/
  screenshots/
    reliability/
  results/
    performance_raw.csv
    performance_summary.csv
    run_metadata.json
    reliability_raw.csv
    reliability_summary.csv  # after manual grading and summarization

About

Companion examples and benchmarks for the Screenshot Scout PHP screenshot article.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages