SDK · PHP

PHP

Official Bugwatch SDK for PHP 8.1+. Zero dependencies (curl extension only). Events are queued on a curl multi handle and flushed on shutdown, so your request is never delayed.

Install

PHP
// No Composer server yet — require the single file directly:
require __DIR__ . '/Bugwatch.php';

// With Composer (once published):
// composer require roomylabs/bugwatch-php

Quickstart

PHP
<?php
require __DIR__ . '/Bugwatch.php';

Bugwatch::init('https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1');

try {
    risky_operation();
} catch (Throwable $e) {
    Bugwatch::captureException($e);
}

Bugwatch::captureMessage('Payment gateway timed out', 'warning');

// Context
Bugwatch::addBreadcrumb('db', 'SELECT * FROM users');
Bugwatch::setTag('region', 'eu-west');
Bugwatch::setUser(42, 'alice@example.com'); // email masked before sending

// flush() is auto-called at shutdown — the request is never delayed.

Behaviour

  • Non-blocking — events are queued on a curl multi handle and flushed on flush() or PHP shutdown.
  • HTTPS enforced http:// DSNs are rejected unless BUGWATCH_ALLOW_HTTP=1 (local testing).
  • PII masking setUser() masks the email local part (alice@x.com a****@x.com).
  • Silent no-op — if not initialised, every call returns null and never throws; the SDK can never break your application.
  • Breadcrumbs — last 100 kept.

API

APIDescription
init(string $dsn): voidConfigure with your project DSN.
captureException(Throwable $e): ?stringSend an exception, returns the event id.
captureMessage(string $msg, string $level = 'error'): ?stringSend a message.
addBreadcrumb(string $category, string $message): voidAdd a breadcrumb.
setUser(?int $id, ?string $email = null): voidAttach the acting user.
setTag(string $key, string $value): voidAttach a tag.
flush(): boolWait for pending sends (auto-called at shutdown).