PHPackages                             peekapi/peekapi - 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. [API Development](/categories/api)
4. /
5. peekapi/peekapi

ActiveLibrary[API Development](/categories/api)

peekapi/peekapi
===============

Zero-dependency PHP SDK for PeekAPI — PSR-15 and Laravel middleware for API analytics

v0.1.0(2mo ago)10MITPHPPHP &gt;=8.2CI passing

Since Mar 4Pushed 2mo agoCompare

[ Source](https://github.com/peekapi-dev/sdk-php)[ Packagist](https://packagist.org/packages/peekapi/peekapi)[ Docs](https://github.com/peekapi-dev/sdk-php)[ GitHub Sponsors](https://github.com/peekapi-dev)[ RSS](/packages/peekapi-peekapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

PeekAPI — PHP SDK
=================

[](#peekapi--php-sdk)

[![Packagist](https://camo.githubusercontent.com/78b40b4bff78ba707102dcf86ec6268a3f194af63605d1d7721aa27a6852eb16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7065656b6170692f7065656b617069)](https://packagist.org/packages/peekapi/peekapi)[![license](https://camo.githubusercontent.com/d987706c2b0bc6cd3c2f99dcf2b465754e0424826c655fb992a5e95485f89cf2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7065656b6170692f7065656b617069)](./LICENSE)[![CI](https://github.com/peekapi-dev/sdk-php/actions/workflows/ci.yml/badge.svg)](https://github.com/peekapi-dev/sdk-php/actions/workflows/ci.yml)

Zero-dependency PHP SDK for [PeekAPI](https://peekapi.dev). PSR-15 middleware for Slim/Mezzio and a dedicated Laravel middleware with auto-configuration from env vars.

Install
-------

[](#install)

```
composer require peekapi/peekapi
```

Quick Start
-----------

[](#quick-start)

### Laravel

[](#laravel)

Set environment variables and register the middleware:

```
# .env
PEEKAPI_API_KEY=ak_live_xxx
PEEKAPI_ENDPOINT=https://...
```

```
// bootstrap/app.php (Laravel 11+)
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\PeekApi\Middleware\Laravel::class);
})
```

```
// Or app/Http/Kernel.php (Laravel 10)
protected $middleware = [
    \PeekApi\Middleware\Laravel::class,
    // ...
];
```

The Laravel middleware auto-configures from `PEEKAPI_API_KEY` and `PEEKAPI_ENDPOINT` env vars.

### Slim (PSR-15)

[](#slim-psr-15)

```
use PeekApi\Client;
use PeekApi\Middleware\PSR15;
use Slim\Factory\AppFactory;

$client = new Client([
    'api_key' => 'ak_live_xxx',
]);

$app = AppFactory::create();
$app->add(new PSR15($client));

$app->get('/api/hello', function ($request, $response) {
    $response->getBody()->write(json_encode(['message' => 'hello']));
    return $response->withHeader('Content-Type', 'application/json');
});

$app->run();
```

### Mezzio (PSR-15)

[](#mezzio-psr-15)

```
// config/pipeline.php
use PeekApi\Client;
use PeekApi\Middleware\PSR15;

$client = new Client(['api_key' => 'ak_live_xxx']);
$app->pipe(new PSR15($client));
```

### Standalone Client

[](#standalone-client)

```
use PeekApi\Client;

$client = new Client(['api_key' => 'ak_live_xxx']);

$client->track([
    'method' => 'GET',
    'path' => '/api/users',
    'status_code' => 200,
    'response_time_ms' => 42,
]);

// Graceful shutdown (flushes remaining events)
$client->shutdown();
```

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

[](#configuration)

OptionDefaultDescription`api_key`requiredYour PeekAPI key`endpoint`PeekAPI cloudIngestion endpoint URL`flush_interval``10`Seconds between automatic flushes`batch_size``100`Events per HTTP POST (triggers flush)`max_buffer_size``10_000`Max events held in memory`max_storage_bytes``5_242_880`Max disk fallback file size (5MB)`max_event_bytes``65_536`Per-event size limit (64KB)`storage_path`autoCustom path for JSONL persistence file`debug``false`Enable debug logging to stderr`on_error``null`Callback `callable(Throwable): void` for flush errorsHow It Works
------------

[](#how-it-works)

1. Middleware intercepts every request/response
2. Captures method, path, status code, response time, request/response sizes, consumer ID
3. Events are buffered in memory and flushed synchronously when `batchSize` is reached
4. On network failure: exponential backoff with jitter, up to 5 retries
5. After max retries: events are persisted to a JSONL file on disk
6. On next startup: persisted events are recovered and re-sent
7. On shutdown: `register_shutdown_function` flushes remaining events or persists to disk

Consumer Identification
-----------------------

[](#consumer-identification)

By default, consumers are identified by:

1. `X-API-Key` header — stored as-is
2. `Authorization` header — hashed with SHA-256 (stored as `hash_`)

Override with the `identify_consumer` option to use any header:

```
$client = new PeekApi\Client([
    'api_key' => '...',
    'identify_consumer' => fn(array $headers) => $headers['x-tenant-id'] ?? null,
]);
```

The callback receives an associative array of lowercase header names and should return a consumer ID string or `null`.

Features
--------

[](#features)

- **Zero runtime dependencies** — uses only `ext-curl` and `ext-json`
- **Disk persistence** — undelivered events saved to JSONL, recovered on restart
- **Exponential backoff** — with jitter, max 5 consecutive failures before disk fallback
- **SSRF protection** — private IP blocking, HTTPS enforcement (HTTP only for localhost)
- **Input sanitization** — path (2048), method (16), consumer\_id (256) truncation
- **Per-event size limit** — strips metadata first, drops if still too large (default 64KB)
- **Graceful shutdown** — `register_shutdown_function` + `__destruct` fallback
- **PSR-15 compatible** — works with any PSR-15 framework
- **Laravel auto-config** — reads from `PEEKAPI_API_KEY` / `PEEKAPI_ENDPOINT` env vars

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

[](#requirements)

- PHP &gt;= 8.2
- `ext-curl`
- `ext-json`

Contributing
------------

[](#contributing)

Bug reports and feature requests: [peekapi-dev/community](https://github.com/peekapi-dev/community/issues)

1. Fork &amp; clone the repo
2. Install dependencies — `composer install`
3. Run tests — `composer exec phpunit`
4. Submit a PR

Support
-------

[](#support)

If you find PeekAPI useful, give this repo a star — it helps others discover the project.

### Badge

[](#badge)

Show that your API is monitored by PeekAPI:

```
[![Monitored by PeekAPI](https://img.shields.io/badge/monitored%20by-PeekAPI-06b6d4)](https://peekapi.dev)
```

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance86

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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

Unknown

Total

1

Last Release

75d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/920138026d1e82d72c1d885866327c105ab30b65fc2835fdcdffc323a8f6e33f?d=identicon)[KonstantinKai](/maintainers/KonstantinKai)

---

Top Contributors

[![KonstantinKai](https://avatars.githubusercontent.com/u/2514038?v=4)](https://github.com/KonstantinKai "KonstantinKai (10 commits)")

---

Tags

api-analyticsapi-monitoringlaravelmiddlewareobservabilityphppsr-15rest-apislimmiddlewareapilaravelpsr-15analyticspeekapi

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/peekapi-peekapi/health.svg)

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

###  Alternatives

[reindert-vetter/api-version-control

A Laravel package to manage versions of endpoints in an elegant way

1671.0M](/packages/reindert-vetter-api-version-control)[ozankurt/google-analytics

Laravel Google Analytics

7616.7k](/packages/ozankurt-google-analytics)[imliam/laravel-throttle-simultaneous-requests

Throttle the current user's requests based on how many requests are currently being executed.

4623.0k](/packages/imliam-laravel-throttle-simultaneous-requests)[siro/php-klaviyo-api

Low level but elegant Klaviyo full API wrapper for PHP with asynchronous track event support

16115.4k](/packages/siro-php-klaviyo-api)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[still-code/laravel-umami

Umami API wrapper for laravel

362.5k](/packages/still-code-laravel-umami)

PHPackages © 2026

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