PHP SDK
Plain PHP and other frameworks
composer require watchtower15/sdkThe core needs PHP 8.3 or later, ext-curl and ext-json; ext-zlib is optional (with it the SDK gzips what it sends).
The client
Section titled “The client”use WatchTower15\Client;
$wt15 = Client::fromEnvironment(); // WT15_API_KEY, WT15_METRICS_TOKEN, WT15_LOGS_TOKENSee 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.
Metrics
Section titled “Metrics”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.
# crontab* * * * * cd /app && vendor/bin/watchtower15 flush --bootstrap=config/wt15-metrics.phpServerless
Section titled “Serverless”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]]);Your own HTTP client
Section titled “Your own HTTP client”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.