PHP SDK

Install the Logdash PHP SDK, send your first log and your first metric.

Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the PHP SDK README.

Install

composer require logdash/php-sdk

Initialise

Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.

<?php

require_once 'vendor/autoload.php';

use Logdash\Logdash;

$logdash = Logdash::create([
    'apiKey' => $_ENV['LOGDASH_API_KEY'] ?? '',
]);

$logger = $logdash->logger();
$metrics = $logdash->metrics();

Send a log

$logger->error('Application error occurred');
$logger->warn('This is a warning message');
$logger->info('User logged in successfully');

Send a metric

Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.

$metrics->set('active_users', 150);
$metrics->mutate('login_count', 1); // Increment by 1
$metrics->mutate('error_count', -1); // Decrement by 1

Works with

  • Laravel
  • Symfony
  • Slim
  • WordPress
  • Plain PHP

FAQ

What happens if Logdash is unreachable?

Nothing breaks. The SDK is non-blocking and fails silently in production, local logging keeps working, and API errors are only surfaced when you pass `verbose => true`.

How do I use it in Laravel?

Bind it as a singleton in a service provider with `Logdash::create([...])`, then call `app("logdash")->logger()`. Symfony gets the same object through a `services.yaml` factory.

Which PHP version does it need?

PHP 8.1 or higher, tested on 8.1, 8.2 and 8.3. Composer pulls in the Guzzle HTTP client for you.