PHP SDK
emitwave/php — a framework-independent PHP SDK for publishing signed events.
Server SDK· 4 min read
Install
bash
composer require emitwave/php
Requires PHP 8.3+, the cURL extension for the built-in transport, an application ID, and an active server credential. Server secrets must remain on trusted servers.
publicKey and secret are an application server credential — different from the browser public application key. The SDK hashes the exact JSON body and HMAC-signs each publish request.Publish an event
trigger() accepts any external channel name. The default client uses cURL plus Nyholm PSR-7 factories.
publish.php
<?php require __DIR__.'/vendor/autoload.php'; use Emitwave\Client; $emitwave = new Client( appId: $_ENV['EMITWAVE_APP_ID'], publicKey: $_ENV['EMITWAVE_KEY'], secret: $_ENV['EMITWAVE_SECRET'], // gatewayUrl defaults to https://api.emitwave.com ); $emitwave->trigger('orders', 'order.created', [ 'id' => 'ord_123', 'total' => 4900, ]);
Custom PSR-18 transport
Inject a PSR-18 client and matching PSR-17 factories when your application already has an HTTP stack.
transport.php
$emitwave = new Client( $gatewayUrl, $appId, $publicKey, $secret, $psr18Client, $requestFactory, $streamFactory, );
Error handling
Non-2xx responses and payload encoding failures throw EmitwaveException. The exception does not include the credential secret.
errors.php
use Emitwave\EmitwaveException; try { $emitwave->trigger('orders', 'order.created', ['id' => 'ord_123']); } catch (EmitwaveException $error) { error_log("Emitwave rejected the event: HTTP {$error->status}"); error_log($error->body); }
This SDK sends the supplied JSON payload unchanged. For a private-encrypted channel, create a compatible ciphertext envelope first — see Encryption. Using Laravel? See the Laravel SDK.