PHP Quick Start
Get started with the Browser7 PHP SDK in minutes.
Prerequisites
- PHP 8.0+
- Composer
- A Browser7 API key from the Dashboard
Basic Usage
<?php
require 'vendor/autoload.php';
use Browser7\Browser7Client;
$client = new Browser7Client('b7_your_api_key_here');
$result = $client->render('https://example.com');
echo $result->html;
Geo-Targeting
Target a specific country or city for rendering.
// Target a country
$result = $client->render('https://example.com', [
'countryCode' => 'DE'
]);
// Target a specific city
$result = $client->render('https://example.com', [
'countryCode' => 'US',
'city' => 'new.york'
]);
See Supported Countries for all available country codes and cities.
Wait Actions
Control how the browser waits for dynamic content before capturing the page.
use Browser7\Browser7Client;
use Browser7\WaitAction;
$client = new Browser7Client('b7_your_api_key_here');
$result = $client->render('https://example.com', [
'waitFor' => [
WaitAction::click('.cookie-accept'), // Dismiss cookie banner
WaitAction::selector('.main-content'), // Wait for content to appear
WaitAction::text('In Stock', '.availability'), // Wait for specific text
]
]);
Screenshots
// Viewport screenshot (JPEG, default)
$result = $client->render('https://example.com', [
'includeScreenshot' => true
]);
// Full page PNG screenshot
$result = $client->render('https://example.com', [
'includeScreenshot' => true,
'screenshotFormat' => 'png',
'screenshotFullPage' => true
]);
// Save to file
file_put_contents('screenshot.png', base64_decode($result->screenshot));
Performance Options
Block images for faster renders (enabled by default):
$result = $client->render('https://example.com', [
'blockImages' => true // Default - skip this for image-heavy pages
]);
CAPTCHA Solving
// Auto-detect and solve any CAPTCHA
$result = $client->render('https://example.com', [
'captcha' => 'auto'
]);
// Target a specific CAPTCHA type
$result = $client->render('https://example.com', [
'captcha' => 'recaptcha_v2'
]);
See CAPTCHA Solving for more.
Progress Callbacks
Track render progress with a callable:
$result = $client->render('https://example.com', [
'onProgress' => function (array $event) {
echo "[{$event['type']}] " . ($event['status'] ?? '') . PHP_EOL;
}
]);
Error Handling
try {
$result = $client->render('https://example.com');
echo $result->html;
} catch (\RuntimeException $e) {
echo 'Error: ' . $e->getMessage();
}
RenderResult
A successful render returns a RenderResult object:
$result->status // 'completed', 'processing', or 'failed'
$result->html // Rendered HTML (automatically decompressed)
$result->screenshot // Base64-encoded image (if includeScreenshot was true)
$result->selectedCity // Array with city info used for rendering
$result->bandwidthMetrics // Array with network stats
$result->captcha // Array with CAPTCHA detection info
$result->timingBreakdown // Array with performance timings
$result->fetchResponses // Array of fetch responses (if fetchUrls provided)
$result->retryAfter // Server-suggested retry interval in seconds
$result->error // Error message if status is 'failed'
Next Steps
- API Reference - Complete method and type documentation
- Examples - Copy-paste ready examples for common use cases
- Advanced API - Direct REST API usage