# PHP SDK

The PHP SDK calls the [WatchTower15 API](https://developer.watchtower15.com/), counts what your application does as [custom metrics](https://docs.watchtower15.com/metrics/sources/) and ships its logs to [log ingest](https://docs.watchtower15.com/logs/custom-sources/), from one `Client`. It builds, retries and batches the calls for you, and turns every failure into a typed exception.

## What it covers

-   **The REST API.** Every `/v1` operation is a method on a service: `$wt15->servers->list()`, `$wt15->incidents->acknowledge($uuid)`. See [the REST API](https://developer.watchtower15.com/sdks/php/api/).
-   **Custom metrics.** Push points, or count in the request path with the aggregator and let a flush send them once a minute. See [custom metrics](https://developer.watchtower15.com/sdks/php/metrics/).
-   **Logs.** A Monolog handler and a PSR-3 logger that send lines to log ingest. See [logs](https://developer.watchtower15.com/sdks/php/logs/).

## Which package to install

| You use | Install | Page |
| --- | --- | --- |
| Laravel 12 or 13 | `composer require watchtower15/laravel` | [Laravel](https://developer.watchtower15.com/sdks/php/laravel/) |
| Symfony 6.4, 7.4 or 8 | `composer require watchtower15/symfony` | [Symfony](https://developer.watchtower15.com/sdks/php/symfony/) |
| CakePHP 5.1 or later | `composer require watchtower15/cakephp` | [CakePHP](https://developer.watchtower15.com/sdks/php/cakephp/) |
| Anything else | `composer require watchtower15/sdk` | [Plain PHP and other frameworks](https://developer.watchtower15.com/sdks/php/other-frameworks/) |

A bridge requires the core, `watchtower15/sdk`, so you install one package. All four are released together, at one version.

## Support

PHP 8.3 and later, until each minor’s own security support ends. Laravel 12 and 13; Symfony 6.4, 7.4 and 8.x (8.x on PHP 8.4 and later); CakePHP 5.1 and later. The SDK follows [Semantic Versioning](https://semver.org), independently of the API’s `v1`: a new API operation is additive and ships in the next release, and a change to the SDK’s own signatures is a major one. The full policy and the tested versions are in the [package README](https://github.com/watchtower15/watchtower15-php#support-policy).

## The three credentials

Each credential is created in the console and is good for one job. The SDK checks its shape before it sends anything, and names a credential given in the wrong place.

| Credential | Variable | Used for | Created |
| --- | --- | --- | --- |
| API key `wt15ak_…` | `WT15_API_KEY` | `me()` and the REST API. Personal: keep it out of shared code. | [Authentication and keys](https://developer.watchtower15.com/api/authentication/) |
| Metric source token `wt15ms_…` | `WT15_METRICS_TOKEN` | Pushing and listing custom metrics | [Metric sources](https://docs.watchtower15.com/metrics/sources/) |
| Log source token `wt15ls_…` | `WT15_LOGS_TOKEN` | Pushing log lines | [Custom log sources](https://docs.watchtower15.com/logs/custom-sources/) |

Credentials are never logged, never put in an exception message and never serialised; a dump of a `Client` shows each as its prefix and last four characters.

## On a host that runs the agent

If the WatchTower15 agent runs on the host, let it tail your log files: no token in the application and no HTTP from PHP. Use the SDK’s log handler where the agent does not run.

## Check the setup

```bash
export WT15_API_KEY=… WT15_METRICS_TOKEN=… WT15_LOGS_TOKEN=…
vendor/bin/watchtower15 test
```

The Laravel, Symfony and CakePHP bridges have their own `test` command, which reads the framework’s configuration.

Source: https://developer.watchtower15.com/sdks/php/
