PHP

PHP

The replaystack-php-sdk repository publishes replaystack/sdk on Packagist. It targets PHP 8.1+, aligns wire format with the TypeScript and Python clients, and includes first-class Laravel, Symfony, and Slim integrations plus PSR-15 middleware.

Install

Require the library with Composer, then autoload as usual. Full requirements (extensions, framework docs) live in the repository README.

Composer
composer require replaystack/sdk

Minimal client

Configuration

ReplayStack\\Sdk\\Config accepts the same concepts as other SDKs (API key, endpoint, service name, sampling, masking, ignored paths). See Authentication for env var names and the repository README for the full constructor reference.
ReplayStack + ProcessGuards
<?php

use ReplayStack\Sdk\Config;
use ReplayStack\Sdk\ReplayStack;
use ReplayStack\Sdk\Runtime\ProcessGuards;

$client = new ReplayStack(new Config(
    apiKey: getenv('REPLAYSTACK_API_KEY') ?: null,
    endpoint: getenv('REPLAYSTACK_ENDPOINT') ?: null,
    serviceName: getenv('REPLAYSTACK_SERVICE_NAME') ?: 'my-service',
    environment: getenv('REPLAYSTACK_ENVIRONMENT') ?: 'production',
    appVersion: getenv('REPLAYSTACK_APP_VERSION') ?: null,
    commitHash: getenv('REPLAYSTACK_COMMIT_HASH') ?: null,
));

// Optional: uncaught exceptions, fatal errors, shutdown flush
ProcessGuards::install($client);

Capture

captureEvent
$client->captureEvent([
    'eventType' => 'custom',
    'endpoint' => 'health-check',
    'status' => 'success',
    'statusCode' => 200,
]);
captureException
try {
    riskyOperation();
} catch (\Throwable $e) {
    $client->captureException($e, [
        'endpoint' => '/checkout',
        'statusCode' => 500,
    ]);
    throw $e;
}

Frameworks

Laravel publishes config via vendor:publish; Symfony uses ReplayStackBundle; Slim and other stacks use PSR-15 middleware. Follow docs/LARAVEL.md, docs/SYMFONY.md, and docs/SLIM.md in the repo.

Treat ingestion as best-effort: the SDK buffers and retries, but your app should never depend on ReplayStack availability for the success path.