PHPackages                             logdbhq/logdb-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. logdbhq/logdb-php

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

logdbhq/logdb-php
=================

LogDB SDK for PHP. Universal OTLP HTTP/JSON writer for Laravel, Symfony, Monolog, and standalone PHP services.

v0.2.0-alpha.0(1mo ago)02MITPHPPHP ^8.1CI passing

Since Apr 19Pushed 1mo agoCompare

[ Source](https://github.com/logdbhq/logdb-php)[ Packagist](https://packagist.org/packages/logdbhq/logdb-php)[ Docs](https://github.com/logdbhq/logdb-php)[ RSS](/packages/logdbhq-logdb-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

logdbhq/logdb-php
=================

[](#logdbhqlogdb-php)

[![Packagist Version](https://camo.githubusercontent.com/6584224f00dbcc8e278d872c3751960887b18b09184df949555cb68cbec6c9e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f67646268712f6c6f6764622d7068703f696e636c7564655f70726572656c656173657326636f6c6f723d626c7565)](https://packagist.org/packages/logdbhq/logdb-php)[![PHP](https://camo.githubusercontent.com/525e4764582ea6ef05f016422eb73b013982ded6b72f967e889d313c7499bd0c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6f67646268712f6c6f6764622d7068703f636f6c6f723d383839326266)](https://www.php.net/)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

Universal LogDB SDK for PHP. Ships logs, heartbeats, and cache entries to LogDB over OTLP HTTP/JSON. Drops into any PHP runtime that has `ext-curl` — Laravel, Symfony, WordPress, queue workers, plain PHP scripts.

- **PSR-3 first** — `LogDBClient` implements `Psr\Log\LoggerInterface`. Plug into anything that speaks PSR-3.
- **Monolog handler included** — one line to ship every Monolog record into LogDB.
- **Laravel service provider auto-discovered** — `composer require` and you're done.
- **Zero hard dependencies** beyond `psr/log`. Uses `ext-curl` directly. No Guzzle, no Symfony HttpClient, no protobuf compiler.
- **Same API as `@logdbhq/node` / `@logdbhq/web` / `LogDB.SDK` (.NET)** — mixed-stack apps look identical on every side.

> **Status:** alpha. The wire format and resilience defaults are stable; the public API may still tighten in 0.x.

Install
-------

[](#install)

```
composer require logdbhq/logdb-php:^0.1@alpha
```

PHP **8.1+** required. `ext-curl` and `ext-json` must be available.

30-second start
---------------

[](#30-second-start)

```
use LogDB\LogDBClient;
use LogDB\Options\LogDBClientOptions;

$client = new LogDBClient(new LogDBClientOptions(
    endpoint: 'https://otlp.logdb.site',
    apiKey: getenv('LOGDB_API_KEY'),
    defaultApplication: 'my-service',
    defaultEnvironment: 'production',
));

// PSR-3 ergonomics
$client->info('user logged in', [
    'user_email' => 'alice@example.com',
    'correlation_id' => 'trace-abc-123',
    'tenant' => 'acme',
]);

// Errors with throwable context
try {
    chargeCard($cart);
} catch (\Throwable $e) {
    $client->error('payment failed', ['exception' => $e]);
}

// Drain on shutdown is automatic; or call explicitly:
$client->dispose();
```

Laravel
-------

[](#laravel)

The service provider is auto-discovered. Set the API key in `.env`:

```
LOGDB_API_KEY=your-key-here
LOGDB_ENDPOINT=https://otlp.logdb.site
LOGDB_APPLICATION=my-laravel-app

```

Add a logging channel to `config/logging.php`:

```
'logdb' => [
    'driver' => 'monolog',
    'handler' => \LogDB\Integrations\Monolog\LogDBHandler::class,
],
```

Use it anywhere:

```
use Illuminate\Support\Facades\Log;

Log::channel('logdb')->info('user signed up', [
    'user_email' => $user->email,
    'plan' => $user->plan,
]);
```

(Optional) publish the config to tweak batching / retry / circuit-breaker settings:

```
php artisan vendor:publish --tag=logdb-config
```

Monolog (standalone)
--------------------

[](#monolog-standalone)

```
use LogDB\Integrations\Monolog\LogDBHandler;
use Monolog\Logger;

$logger = new Logger('app');
$logger->pushHandler(new LogDBHandler($logdbClient));

$logger->error('order failed', ['exception' => $e, 'order_id' => 42]);
```

Monolog levels map to LogDB levels:

MonologLogDB`Debug``Debug``Info`, `Notice``Info``Warning``Warning``Error``Error``Critical`, `Alert`, `Emergency``Critical`Builder API
-----------

[](#builder-api)

For full-fidelity sends (typed attribute maps, labels, structured HTTP fields):

```
use LogDB\Builders\LogEventBuilder;
use LogDB\Models\LogLevel;

LogEventBuilder::create($client)
    ->setMessage('checkout completed')
    ->setLogLevel(LogLevel::Info)
    ->setUserEmail('alice@example.com')
    ->setCorrelationId($traceId)
    ->setRequestPath('/api/checkout')
    ->setHttpMethod('POST')
    ->setStatusCode(200)
    ->addAttribute('amount_eur', 199.99)         // → attributesN
    ->addAttribute('currency', 'EUR')            // → attributesS
    ->addAttribute('verified', true)             // → attributesB
    ->addAttribute('completed_at', new DateTimeImmutable())   // → attributesD
    ->addLabel('payment')
    ->addLabel('checkout')
    ->log();
```

Heartbeats / measurements:

```
use LogDB\Builders\LogBeatBuilder;

LogBeatBuilder::create($client)
    ->setMeasurement('queue.depth')
    ->addTag('queue', 'orders.confirmed')
    ->addField('depth', 1247)
    ->log();
```

Key/value cache writes:

```
use LogDB\Builders\LogCacheBuilder;

LogCacheBuilder::create($client)
    ->setKey('user:42:profile')
    ->setValue(['name' => 'Alice', 'plan' => 'pro'])
    ->log();
```

Configuration
-------------

[](#configuration)

Every option has a sensible default. Pass them by name:

```
new LogDBClientOptions(
    endpoint: 'https://otlp.logdb.site',
    apiKey: getenv('LOGDB_API_KEY'),
    defaultApplication: 'checkout-service',
    defaultEnvironment: 'production',
    defaultCollection: 'logs',

    // batching
    enableBatching: true,
    batchSize: 100,
    flushInterval: 5_000,           // ms

    // retry
    maxRetries: 3,
    retryDelay: 1_000,              // ms
    retryBackoffMultiplier: 2.0,

    // circuit breaker
    enableCircuitBreaker: true,
    circuitBreakerFailureThreshold: 0.5,
    circuitBreakerSamplingDuration: 10_000,
    circuitBreakerDurationOfBreak: 30_000,

    // transport
    requestTimeout: 30_000,         // ms
    headers: ['x-team' => 'platform'],

    // diagnostics
    enableDebugLogging: false,
    onError: fn (\Throwable $e, ?array $batch) => error_log("logdb: {$e->getMessage()}"),

    // PHP-specific: drain pending logs at request shutdown
    flushOnShutdown: true,
)
```

Error model
-----------

[](#error-model)

Sends never throw on transient failures — they retry internally and surface a status code. For total visibility, register an `onError` callback or read the return value:

```
use LogDB\Models\LogResponseStatus;

$status = $client->logEntry($log);

match ($status) {
    LogResponseStatus::Success => null,
    LogResponseStatus::NotAuthorized => throw new \RuntimeException('Bad LogDB key'),
    LogResponseStatus::CircuitOpen => $metrics->increment('logdb.circuit_open'),
    LogResponseStatus::Timeout, LogResponseStatus::Failed => $metrics->increment('logdb.failed'),
};
```

Typed exceptions (all extend `LogDB\Errors\LogDBError`):

ClassThrown when`LogDBAuthError`HTTP 401 / 403. Not retried.`LogDBConfigError`HTTP 400 / invalid endpoint URL. Not retried.`LogDBNetworkError`5xx, 429, network failure after retries.`LogDBTimeoutError`Request exceeded `requestTimeout`.`LogDBCircuitOpenError`Circuit breaker rejected without sending.Lifecycle
---------

[](#lifecycle)

The constructor does **no I/O** — the curl handle and OTLP transport open lazily on the first send.

`dispose()` flushes the batch buffer and closes the curl handle. The destructor calls `dispose()` automatically. By default, the client also registers a `register_shutdown_function` callback that flushes pending entries before the PHP request ends — disable with `flushOnShutdown: false` if you want full control.

Sibling SDKs
------------

[](#sibling-sdks)

Same API surface across the LogDB SDK family:

- **`LogDB.SDK`** (.NET) — native gRPC, the reference implementation
- **`@logdbhq/node`** — Node.js, native gRPC
- **`@logdbhq/web`** — universal JS/TS over OTLP HTTP/JSON
- **`logdbhq/logdb-php`** — this package

Documentation
-------------

[](#documentation)

Full docs:

License
-------

[](#license)

[MIT](LICENSE) © LogDB

###  Health Score

33

—

LowBetter than 73% of packages

Maintenance90

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

50d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/821493d588bff9d5add63131eac0617062453e9c828075347107f62f86642f60?d=identicon)[logdbhq](/maintainers/logdbhq)

---

Top Contributors

[![vlapec](https://avatars.githubusercontent.com/u/210176738?v=4)](https://github.com/vlapec "vlapec (7 commits)")

---

Tags

psr-3laravelloggingopentelemetryotlpmonologobservabilitylogdb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/logdbhq-logdb-php/health.svg)

```
[![Health](https://phpackages.com/badges/logdbhq-logdb-php/health.svg)](https://phpackages.com/packages/logdbhq-logdb-php)
```

###  Alternatives

[inpsyde/wonolog

Monolog-based logging package for WordPress.

184631.3k7](/packages/inpsyde-wonolog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
