PHPackages                             usekamori/kamori-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. usekamori/kamori-php

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

usekamori/kamori-php
====================

PHP SDK for Kamori — self-hosted log ingestion

00PHPCI passing

Since Jun 27Pushed todayCompare

[ Source](https://github.com/usekamori/kamori-php)[ Packagist](https://packagist.org/packages/usekamori/kamori-php)[ RSS](/packages/usekamori-kamori-php/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (1)Used By (0)

kamori-php
==========

[](#kamori-php)

PHP 8.1+ SDK for [Kamori](https://github.com/usekamori/kamori) — self-hosted log ingestion.

Sends structured log events to a Kamori ingest server over HTTP. No curl required — uses PHP's built-in `fopen` stream context for explicit response header access. Supports batching, automatic retry with exponential back-off, and drop callbacks. The client auto-flushes buffered events in `__destruct`.

---

Installation
------------

[](#installation)

```
composer require usekamori/kamori-php
```

---

Direct usage
------------

[](#direct-usage)

```
use Kamori\KamoriClient;

$client = new KamoriClient(
    url: 'https://your-kamori-server.com',
    token: 'your-log-token',   // matches INGEST_TOKEN on the server
    batchSize: 50,             // flush automatically every 50 events
);

$client->log([
    'level'   => 'info',
    'message' => 'User signed in',
    'user_id' => 42,
]);

// Always flush at the end of a request or script
$client->flush();
```

### Flush on shutdown (CLI scripts)

[](#flush-on-shutdown-cli-scripts)

```
register_shutdown_function([$client, 'flush']);
```

---

Monolog 3 handler
-----------------

[](#monolog-3-handler)

```
composer require monolog/monolog
```

```
use Kamori\Monolog\KamoriHandler;
use Monolog\Logger;
use Monolog\Level;

$logger = new Logger('app');
$logger->pushHandler(new KamoriHandler(
    url: 'https://your-kamori-server.com',
    token: 'your-log-token',
    batchSize: 50,
    level: Level::Debug,
));

$logger->info('Hello from Monolog', ['user_id' => 7]);
$logger->error('Something went wrong', ['exception' => 'RuntimeException']);

// Flush when the handler is closed (called automatically by Monolog on __destruct)
// Or flush explicitly:
$logger->getHandlers()[0]->getClient()->flush();
```

Context and extra fields are forwarded to Kamori as-is so all structured data is full-text-searchable.

---

Laravel (zero-config)
---------------------

[](#laravel-zero-config)

Auto-discovery is enabled via `composer.json`. After `composer require usekamori/kamori-php`, add to your `.env`:

```
KAMORI_URL=https://your-kamori-server.com
INGEST_TOKEN=your-log-token
```

Optionally publish the config file:

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

This creates `config/kamori.php` where you can adjust `batch_size`.

The `KamoriClient` singleton is automatically flushed at the end of every request via `app()->terminating()`. No additional setup is required.

### Resolve the client manually

[](#resolve-the-client-manually)

```
use Kamori\KamoriClient;

$client = app(KamoriClient::class);
$client->log(['level' => 'debug', 'message' => 'Manual log entry']);
```

---

Configuration reference
-----------------------

[](#configuration-reference)

OptionDefaultDescription`url`—Base URL of your Kamori server (required)`token``null`Auth token (sent as `Authorization: Bearer`). Leave `null` to skip auth.`batchSize``50`Number of events buffered before auto-flush`maxBuffer``0`Max events in the in-memory buffer. `0` = unlimited. New events are passed to `onDrop` and discarded when the limit is reached.`onDrop``null`Callable invoked with the batch when all retries fail---

Scoped clients
--------------

[](#scoped-clients)

Add default fields to every log call without repeating them:

```
class ScopedKamoriClient
{
    public function __construct(
        private KamoriClient $client,
        private array $defaults = [],
    ) {}

    public function log(array $event): void
    {
        $this->client->log(array_merge($this->defaults, $event));
    }

    public function flush(): void
    {
        $this->client->flush();
    }
}

$requestLog = new ScopedKamoriClient($client, [
    'service'    => 'api',
    'request_id' => 'abc-123',
    'user_id'    => 42,
]);

$requestLog->log(['level' => 'info', 'message' => 'Request started']);
$requestLog->log(['level' => 'error', 'message' => 'Validation failed', 'field' => 'email']);
```

---

Retry behaviour
---------------

[](#retry-behaviour)

Failed requests are retried up to three times with exponential back-off. PHP has no async I/O, so retries block the current process with `usleep()`:

AttemptDelay1st retry0.25 s2nd retry1 s3rd retry4 s`4xx` responses are **not** retried (client error — bad token, oversized batch). After all retries fail the batch is passed to `onDrop` (if configured) and discarded. The client never throws.

---

onDrop callback
---------------

[](#ondrop-callback)

```
$client = new KamoriClient(
    url: 'https://your-kamori-server.com',
    token: 'your-log-token',
    onDrop: function (array $events): void {
        error_log('Kamori dropped ' . count($events) . ' events');
    },
);
```

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- `openssl` extension (enabled by default) for HTTPS
- Monolog 3.x (optional, only needed for `KamoriHandler`)
- Laravel 10+ (optional, only needed for `KamoriServiceProvider`)

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278922930?v=4)[Logs your AI can actually query](/maintainers/usekamori)[@usekamori](https://github.com/usekamori)

---

Top Contributors

[![usekamori](https://avatars.githubusercontent.com/u/278922930?v=4)](https://github.com/usekamori "usekamori (1 commits)")

### Embed Badge

![Health badge](/badges/usekamori-kamori-php/health.svg)

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B10.9k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1938.5M261](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2326.5M315](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

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