---
title: PHP SDK
description: Install and use the official Trigv PHP client for Laravel apps, WordPress plugins, backend jobs, and payment handlers.
---
# PHP SDK

Use the official Trigv PHP SDK to send push notifications from Laravel apps, WordPress plugins, backend jobs, payment handlers, and plain PHP scripts.

## Install

```
composer require trigv/trigv
```

Requires PHP 8.2+ with the `curl` and `json` extensions.

## Send a notification

```
use Trigv\Client;

$trigv = new Client(['api_key' => getenv('TRIGV_API_KEY')]);

$result = $trigv->sendEvent([
		'channel' => 'general',
		'title' => 'Payment received',
		'description' => 'Order was paid successfully',
		'level' => 'success',
		'event_type' => 'payment.success',
]);

echo $result->event->public_id;
```

## Event fields

| Field | Required | Description |
| --- | :---: | --- |
| `channel` | Yes | Channel slug, such as `general`, `deploys`, or `payments`. |
| `title` | Yes | Push notification title. |
| `description` | No | Body text shown in the notification. |
| `image_url` | No | HTTPS image URL for screenshots, charts, camera snapshots, or previews. |
| `url` | No | Destination URL opened from the notification. |
| `level` | No | `info`, `success`, `warning`, or `error`. Defaults to `info`. |
| `delivery_urgency` | No | `standard` or `time_sensitive`. Defaults to `standard`. |
| `event_type` | No | Free-form event label such as `deploy.completed` or `cron.failed`. |
| `idempotency_key` | No | Deduplication key for safe retries. |

You can pass an array or a `Trigv\SendEventRequest` value object.

## Safe retries with idempotency

```
$result = $trigv->sendEvent([
			'channel' => 'deploys',
			'title' => 'Production deploy complete',
			'idempotency_key' => 'deploy-prod-42',
]);

if ($result->duplicate) {
			// Already accepted earlier.
}
```

## Configuration

| Option | Default | Description |
| --- | --- | --- |
| `api_key` | `TRIGV_API_KEY` | Workspace API key. |
| `base_url` | `https://api.trigv.com/api` | API base URL. |
| `timeout` | `30` | Request timeout in seconds. |
| `max_retries` | `2` | Retry count for retryable failures. |
| `http_client` | cURL | Custom HTTP client for testing or framework integration. |

## Verify the API key

```
$connection = $trigv->verifyConnection();
echo $connection->workspace->name;
```

## Error handling

```
use Trigv\Exception\AuthenticationException;
use Trigv\Exception\NotFoundException;
use Trigv\Exception\RateLimitException;
use Trigv\Exception\ValidationException;

try {
		$trigv->sendEvent(['channel' => 'general', 'title' => 'Hello']);
} catch (ValidationException $e) {
		print_r($e->errors);
} catch (NotFoundException $e) {
		echo 'Channel not found';
} catch (RateLimitException $e) {
		echo $e->retryable ? 'Retry later' : 'Monthly limit reached';
} catch (AuthenticationException $e) {
		echo 'Invalid API key';
}
```

## Good places to use it

- Laravel jobs, commands, listeners, and webhook handlers
- WordPress plugins that need focused push alerts
- Payment, billing, subscription, and operational workflows

<DocsResourceLinks
  packageHref="https://packagist.org/packages/trigv/trigv"
  packageTitle="Composer package"
  packageDescription="Install the official Trigv PHP SDK from Packagist."
  packageLabel="Packagist"
  sourceHref="https://github.com/Trigv/trigv-php"
  sourceDescription="View the PHP SDK source on GitHub."
/>
