1. Go to this page and download the library: Download socketbus/socketbus-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
socketbus / socketbus-php example snippets
use SocketBus\SocketBus;
$config = [
'app_id' => 's-1-J2PCu8g8sAejZeXx',
'secret' => 'cdKBpcruwYQ96kvIaYiorbTFxRDCbVfj'
];
$socketBus = new SocketBus($config);
$channelName = $request->channel_name;
if ($socketBus->isChannelPrivate($channelName)) {
// The channel is private
}
if ($socketBus->isChannelPresence($channelName)) {
// The channel is presence
}
if ($socketBus->isChannelPublic($channelName)) {
// The channel is public
}
$socketId = $request->socket_id;
$channelName = $request->channel_name;
if (/** verifies if user can access the request channel */) {
// returns the token to the client
return [
'auth' => $socketbus->auth($socketId, $channelName)
];
}
$socketId = $request->socket_id;
$channelName = $request->channel_name;
$userId = /** gets the current user id */;
if (/** verifies if user can access the request channel */) {
// returns the data
return $socketbus->authPresence($socketId, $channelName, $userId, true);
}