# Plain PHP and other frameworks

```bash
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).

## The client

```php
use WatchTower15\Client;

$wt15 = Client::fromEnvironment();   // WT15_API_KEY, WT15_METRICS_TOKEN, WT15_LOGS_TOKEN
```

See [configuration](https://developer.watchtower15.com/sdks/php/configuration/) for the options, and [the REST API](https://developer.watchtower15.com/sdks/php/api/) for the calls.

## Logs

Wrap the SDK’s Monolog handler in a `BufferHandler`, or use the PSR-3 logger. See [logs](https://developer.watchtower15.com/sdks/php/logs/).

## Metrics

Build an `Aggregator` over a store and flush once a minute, from cron or at shutdown. See [custom metrics](https://developer.watchtower15.com/sdks/php/metrics/) for the stores and which one fits your runtime.

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

## 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:

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

## 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.

Source: https://developer.watchtower15.com/sdks/php/other-frameworks/
