PHP (server-side)
Trigger events from any PHP backend — Laravel, Symfony, plain PHP, anything.
Install
composer require pusher/pusher-php-serverTrigger an event
<?php
require __DIR__ . '/vendor/autoload.php';
$pusher = new Pusher\Pusher(
'YOUR_APP_KEY',
'YOUR_APP_SECRET',
'YOUR_APP_ID',
[
'host' => 'ws-sa.mawjly.com',
'port' => 443,
'scheme' => 'https',
'cluster' => 'sa',
'useTLS' => true,
],
);
$pusher->trigger('chat', 'message', [
'user' => 'alice',
'text' => 'Hello from PHP!',
]);Batch trigger (up to 10 events per call)
$pusher->triggerBatch([
['name' => 'message', 'channel' => 'chat', 'data' => ['text' => 'one']],
['name' => 'message', 'channel' => 'chat', 'data' => ['text' => 'two']],
['name' => 'typing', 'channel' => 'chat', 'data' => ['user' => 'alice']],
]);Channel info
$res = $pusher->getChannels(['filter_by_prefix' => 'presence-']);
// $res->channels => ['presence-room-1' => ['user_count' => 3], ...]
$info = $pusher->getChannelInfo('presence-room-1', ['info' => 'user_count,subscription_count']);
$members = $pusher->get('/channels/presence-room-1/users');Authorize a private / presence subscription
If your client subscribes to private- or presence- channels, you expose a /broadcasting/auth endpoint that signs the subscription with your secret.
$auth = $pusher->authorizeChannel(
$_POST['channel_name'],
$_POST['socket_id'],
);
echo $auth; // {"auth":"<key>:<hex_signature>"}For presence channels, also pass the user data:
$auth = $pusher->authorizePresenceChannel(
$_POST['channel_name'],
$_POST['socket_id'],
(string) $userId,
[
'name' => $user->name,
'avatar' => $user->avatar_url,
],
);See Authorization endpoints for full examples in PHP, Node, and Laravel.