PHP SDK
PHP SDK
The PHP SDK calls the WatchTower15 API, counts what your application does as custom metrics
and ships its logs to log ingest, from one Client. It builds, retries and batches the calls for
you, and turns every failure into a typed exception.
What it covers
Section titled “What it covers”- The REST API. Every
/v1operation is a method on a service:$wt15->servers->list(),$wt15->incidents->acknowledge($uuid). See the REST 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.
- Logs. A Monolog handler and a PSR-3 logger that send lines to log ingest. See logs.
Which package to install
Section titled “Which package to install”| You use | Install | Page |
|---|---|---|
| Laravel 12 or 13 | composer require watchtower15/laravel |
Laravel |
| Symfony 6.4, 7.4 or 8 | composer require watchtower15/symfony |
Symfony |
| CakePHP 5.1 or later | composer require watchtower15/cakephp |
CakePHP |
| Anything else | composer require watchtower15/sdk |
Plain PHP and other frameworks |
A bridge requires the core, watchtower15/sdk, so you install one package. All four are released together, at one version.
Support
Section titled “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, 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.
The three credentials
Section titled “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 |
Metric source token wt15ms_… |
WT15_METRICS_TOKEN |
Pushing and listing custom metrics | Metric sources |
Log source token wt15ls_… |
WT15_LOGS_TOKEN |
Pushing log lines | Custom log 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
Section titled “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
Section titled “Check the setup”export WT15_API_KEY=… WT15_METRICS_TOKEN=… WT15_LOGS_TOKEN=…vendor/bin/watchtower15 testThe Laravel, Symfony and CakePHP bridges have their own test command, which reads the framework’s configuration.