Skip to content
v1
Docs

PHP SDK

Plain PHP and other frameworks

Terminal window
composer require watchtower15/sdk

The core needs PHP 8.3 or later, ext-curl and ext-json; ext-zlib is optional (with it the SDK gzips what it sends).

use WatchTower15\Client;
$wt15 = Client::fromEnvironment(); // WT15_API_KEY, WT15_METRICS_TOKEN, WT15_LOGS_TOKEN

See configuration for the options, and the REST API for the calls.

Wrap the SDK’s Monolog handler in a BufferHandler, or use the PSR-3 logger. See logs.

Build an Aggregator over a store and flush once a minute, from cron or at shutdown. See custom metrics for the stores and which one fits your runtime.

Terminal window
# crontab
* * * * * cd /app && vendor/bin/watchtower15 flush --bootstrap=config/wt15-metrics.php

Minute buckets do not fit a process the platform freezes after the invocation answers. Use push() at the end of the invocation, and flush the log buffer before it answers:

$wt15->ingest->metrics->push([['metric' => 'jobs.done', 'metric_type' => 'count', 'value' => 1]]);

Pass any PSR-18 client as httpClient, with redirects off. Give it a timeout of at most 10 s if an aggregator uses it, and of at most 3 s (connect 1 s) for log pushes.