Language

PHP Screenshot API

Add screenshot capabilities to PHP applications using cURL or Guzzle HTTP. Perfect for WordPress plugins, Laravel apps, and REST-based web services. Covers authentication, error handling, saving to local storage or S3, and integrating with Laravel queues for background processing.

Quick Start

1

Install dependencies

Ensure cURL extension is enabled in php.ini (enabled by default in most installations).

2

Get your API key

Sign up for Screenshotly and get your API key from the dashboard.

3

Copy the code example

Use our PHP code example as a starting point.

4

Customize and integrate

Modify the code to fit your specific use case and requirements.

Code Example

<?php
// PHP with cURL
function captureScreenshot($url, $outputPath) {
    $ch = curl_init('https://api.screenshotly.app/screenshot');
    
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . $_ENV['SCREENSHOTLY_API_KEY'],
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode([
            'url' => $url,
            'device' => 'desktop',
            'format' => 'png',
        ]),
    ]);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    file_put_contents($outputPath, $response);
}

When to Use PHP with Screenshotly

Use the PHP integration for WordPress plugins, Laravel or Symfony applications, and traditional server-rendered web apps. PHP is the right choice when you need to generate screenshots from a CMS, embed capture functionality in a WordPress admin panel, or build a screenshot feature into an existing LAMP/LEMP stack.

PHP Best Practices

In Laravel, use Http::withToken()->post() for cleaner code than raw cURL. Pair with Laravel Queues (database or Redis) for background processing.

Cache screenshots with WordPress transients or Laravel Cache to avoid redundant API calls for the same URL.

Use curl_setopt($ch, CURLOPT_TIMEOUT, 30) to set a hard timeout — prevents your web server from hanging on slow captures.

For Guzzle users, enable the retry middleware with HandlerStack::create() and new RetryMiddleware() for automatic retry on 429/5xx.

Want a step-by-step walkthrough?

Read the full PHP tutorial →

API Reference

EndpointPOST /api/screenshot
AuthenticationBearer token
Content-Typeapplication/json
View full API docs

Frequently Asked Questions

How do I use Screenshotly with Laravel?

Create a service class that wraps the API call using Laravel's HTTP client: Http::withToken(config('services.screenshotly.key'))->post('https://api.screenshotly.app/screenshot', [...]). Store screenshots in Laravel's filesystem using Storage::put().

How do I handle errors with the PHP cURL integration?

Check the HTTP status code with curl_getinfo($ch, CURLINFO_HTTP_CODE). Handle 401 (invalid key), 429 (rate limited), and 500 (server error) cases. Implement retry logic with exponential backoff for temporary failures.

Can I use Screenshotly in WordPress plugins?

Yes. Use WordPress's wp_remote_post() function instead of cURL for better compatibility. Store API keys in wp_options or constants. Cache screenshots using WordPress transients to avoid redundant API calls.

What's the recommended PHP version for the API integration?

PHP 7.4+ is recommended. The cURL extension is required. For modern projects, consider using Guzzle HTTP client for cleaner code and built-in retry/timeout handling.

Start building with PHP

Get your API key and start capturing screenshots in minutes.

Other Languages