# Configuration

## Create a client

```php
use WatchTower15\Client;

$wt15 = new Client(
    apiKey: 'wt15ak_…',
    metricsToken: 'wt15ms_…',
    logsToken: 'wt15ls_…',
);

// or from the environment
$wt15 = Client::fromEnvironment();
$wt15 = Client::fromEnvironment(timeout: 5.0); // a named argument overrides
```

Give only the credentials you use. A call that needs one you did not give throws a `ConfigurationException` naming the parameter and its variable.

`fromEnvironment()` reads `WT15_API_KEY`, `WT15_METRICS_TOKEN`, `WT15_LOGS_TOKEN`, `WT15_API_URL` and `WT15_INGEST_URL`. For each it takes the first non-empty value of `$_SERVER`, `$_ENV` and `getenv()`, so a framework that fills `$_SERVER` and `$_ENV` without `putenv()` works.

## Options

| Option | Default | Notes |
| --- | --- | --- |
| `apiUrl` | `https://rest.watchtower15.com/v1` | `https` only; `http` for `localhost`, `127.0.0.1` and `[::1]` |
| `ingestUrl` | `https://api.watchtower15.com` | May carry a path prefix for a proxy |
| `timeout` | `15.0` | Seconds, above 0 and at most 300 |
| `connectTimeout` | `2.0` | Seconds, not above `timeout` |
| `maxRetries` | `2` | 0 to 10 |
| `httpClient` | cURL | An `Http\Transport` or any PSR-18 client |
| `logger` | none | A PSR-3 logger |
| `appInfo` | none | `name/version`, added to the `User-Agent` |

Per call, the options `timeout`, `connect_timeout`, `max_retries` and `max_retry_wait` go in an array as the last argument of any call: `$wt15->me(['timeout' => 5.0])`.

## Local credential checks

Before anything is sent, the SDK checks each credential’s shape. A credential in the wrong slot is named and refused (`this is a metric source token (wt15ms_…a91f): pass it as metricsToken`), and a truncated paste never reaches a host.

## The `User-Agent`

The SDK sends one piece of metadata: a `User-Agent` of the form `watchtower15-php/<version> php/<major.minor>`, followed by the framework bridge’s name when one is in use and your `appInfo`. It sends nothing else about your system.

## Your own HTTP client

Pass any PSR-18 client as `httpClient`. The SDK then uses its timeouts and redirects: turn redirects off in your client, or a credential can follow a redirect. The Laravel, Symfony and CakePHP bridges use their framework’s HTTP client.

## Check a configuration

```bash
vendor/bin/watchtower15 test
vendor/bin/watchtower15 test --reachability   # needs no credential
vendor/bin/watchtower15 test --json
```

`test` checks the API key with `me()`, the metrics token with the source’s listing, and the logs token by its format only (log ingest has no read-only call). It reports the clock skew against the answer’s `Date`. It exits 0 when every check passed, 1 when one failed, and 2 when nothing is configured or a variable is malformed. It reads the process environment only, never a framework’s `.env` file.

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