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 unlessBUGWATCH_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
| API | Description |
|---|---|
| init(string $dsn): void | Configure with your project DSN. |
| captureException(Throwable $e): ?string | Send an exception, returns the event id. |
| captureMessage(string $msg, string $level = 'error'): ?string | Send a message. |
| addBreadcrumb(string $category, string $message): void | Add a breadcrumb. |
| setUser(?int $id, ?string $email = null): void | Attach the acting user. |
| setTag(string $key, string $value): void | Attach a tag. |
| flush(): bool | Wait for pending sends (auto-called at shutdown). |
