Learn how to send Signalgrid notifications from PHP applications
Installation
Install the package using Composer:
composer require signalgrid/signalgrid-php
Composer will automatically download the library and make it available through the autoloader.
Basic Usage
To send a notification, create a Signalgrid client and call send().
<?php
require 'vendor/autoload.php';
use Signalgrid\Client;
$signalgrid = new Client("YOUR_CLIENT_KEY");
$signalgrid->send([
"channel" => "YOUR_CHANNEL_TOKEN",
"title" => "Server Alert",
"body" => "Database connection lost",
"type" => "CRIT",
"critical"=> true
]);
Parameters
Parameter
Description
channelChannel token that receives the notification.
titleNotification title.
bodyNotification message.
typeNotification type (INFO, WARN, CRIT, SUCCESS).
criticalSends the notification as a critical alert.
Example: Simple Notification Script
The following example sends a notification when a script finishes.
<?php
require 'vendor/autoload.php';
use Signalgrid\Client;
$signalgrid = new Client("YOUR_CLIENT_KEY");
$signalgrid->send([
"channel" => "YOUR_CHANNEL_TOKEN",
"title" => "Backup Completed",
"body" => "Nightly backup finished successfully",
"type" => "SUCCESS"
]);
This is useful for:
- cron jobs
- deployment scripts
- CI/CD pipelines
- maintenance tasks
Example: Sending a Critical Notification
<?php
require 'vendor/autoload.php';
use Signalgrid\Client;
$signalgrid = new Client("YOUR_CLIENT_KEY");
$signalgrid->send([
"channel" => "YOUR_CHANNEL_TOKEN",
"title" => "Server Down",
"body" => "The web server stopped responding",
"type" => "CRIT",
"critical"=> true
]);
This sends a critical alert that bypasses Do Not Disturb on supported devices.
Using Environment Variables (Recommended)
Avoid hardcoding your client key, use environment variables instead:
$signalgrid = new Client(getenv("SIGNALGRID_CLIENT_KEY"));
Example .env:
SIGNALGRID_CLIENT_KEY=abc123