Skip to main content
Use the official Screenshothis SDK for PHP applications to capture screenshots with comprehensive error handling, type safety, and optimized performance. The SDK provides a clean object-oriented interface and follows PHP best practices.

Installation

Install the SDK using Composer:
PHP version support: The SDK requires PHP 8.0 or higher. For optimal performance and type safety, we recommend using PHP 8.1 or later.

Quick start

Get up and running in three simple steps:
1

Install with Composer

2

Initialize client

3

Capture your first screenshot

Basic usage

Simple screenshot

Capture a basic screenshot with minimal configuration:

Advanced screenshot with options

Configure your screenshot with full control over the output:

Comprehensive error handling

The SDK provides specific exception types for different failure scenarios:

Basic error handling

Handle common errors with try-catch blocks:

Exception types reference

Always implement error handling in production applications. Use the requestId from error responses when contacting support.

Advanced configuration

Custom server URL

Override the default API endpoint for self-hosted instances:

Custom HTTP client configuration

Configure custom HTTP client behavior:

Real-world examples

Laravel integration

Create a Laravel service for screenshot functionality:

Batch processing with queue

Process multiple URLs efficiently using Laravel queues:

Symfony integration

Create a Symfony service for screenshot functionality:

WordPress plugin integration

Create a WordPress plugin service:

Health monitoring

The SDK includes health check endpoints for monitoring your application:

Best practices

  • Use appropriate image formats: WebP for modern browsers, JPEG for smaller sizes, PNG for transparency
  • Implement proper caching strategies using the cacheKey parameter
  • Consider image quality vs file size trade-offs (80-90 quality range is often optimal)
  • Batch multiple requests efficiently with proper rate limiting
  • Use specific selectors to capture only needed content
  • Always wrap API calls in try-catch blocks with specific exception handling
  • Implement retry logic with exponential backoff for transient failures
  • Log request IDs from error responses for debugging and support
  • Provide fallback options when screenshots fail
  • Monitor API quota usage to prevent service disruptions
  • API keys use domain whitelisting—safe to commit to version control
  • Configure allowed domains in your dashboard to control key usage
  • Validate and sanitize URLs before sending to the API
  • Implement rate limiting in your own applications
  • Use environment variables for API keys in production
  • Handle large image data efficiently using streaming when possible
  • Clean up temporary files and resources after processing
  • Monitor memory usage in batch processing scenarios
  • Consider using generators for processing large datasets
  • Implement proper garbage collection in long-running processes

Configuration reference

Image formats

Block resources

Available resource types to block during screenshot capture:
  • Operations\BlockResource::Document - HTML documents
  • Operations\BlockResource::Stylesheet - CSS stylesheets
  • Operations\BlockResource::Image - Images
  • Operations\BlockResource::Media - Audio/video media
  • Operations\BlockResource::Font - Web fonts
  • Operations\BlockResource::Script - JavaScript files
  • Operations\BlockResource::Xhr - XMLHttpRequest calls
  • Operations\BlockResource::Fetch - Fetch API requests

Next steps

API Reference

Explore all available API parameters and response formats

Quickstart Guide

Get started with basic screenshot capture in minutes

Self-hosting

Run Screenshothis on your own infrastructure

GitHub Repository

View source code, report issues, or contribute