Skip to main content

PHP SDK

The official PHP SDK for the Generator Labs API v4.0. Uses strict types throughout with PHPStan level 8 static analysis.

Packagegeneratorlabs/sdk (Packagist)
Minimum versionPHP 8.1+
HTTP clientGuzzle
AutoloadingPSR-4
GitHubgenerator-labs/php-sdk

Installation

composer require generatorlabs/sdk

Usage

<?php

use GeneratorLabs\Client;

$client = new Client('your_account_sid', 'your_auth_token');

// Get a single host
$host = $client->rbl->hosts->get('host_id');

// List all hosts with automatic pagination
$hosts = $client->rbl->hosts->getAll();

// Create a certificate monitor
$monitor = $client->cert->monitors->create([
'name' => 'example.com',
]);

// Responses support array access
echo $host['data']['name'];

Configuration

$client = new Client('your_account_sid', 'your_auth_token', [
'timeout' => 45,
'max_retries' => 5,
'retry_backoff' => 2.0,
]);
OptionDefaultDescription
timeout30Total request timeout in seconds
connect_timeout5TCP connection timeout in seconds
max_retries3Maximum number of retry attempts
retry_backoff1.0Backoff multiplier between retries
base_urlOverride the default API base URL

Webhook Verification

use GeneratorLabs\Webhook;

Webhook::verify($body, $signatureHeader, $secret, $tolerance);

See Using Web Hooks for more details on webhook payloads and signature verification.

Error Handling

The PHP SDK throws GeneratorLabs\Exception errors that you can catch with standard try / catch:

use GeneratorLabs\Client;
use GeneratorLabs\Exception;

try {
$host = $client->rbl->hosts->get('host_id');
} catch (Exception $e) {
echo $e->getMessage();
}

Rate Limit Information

Rate limit details are available on every response:

echo $response->rate_limit->remaining;
echo $response->rate_limit->reset;

See What Are the API Rate Limits? for more information.