1. Go to this page and download the library: Download sangezar/srs-php-client 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/ */
sangezar / srs-php-client example snippets
use SrsClient\Client;
use SrsClient\Config;
use SrsClient\Exception\SrsApiException;
try {
// Create client
$config = new Config('http://your-srs-server:1985');
$client = new Client($config);
// Get list of streams
$streams = $client->getStreams();
foreach ($streams as $stream) {
echo "Stream: " . $stream->getName() . "\n";
echo "Clients: " . $stream->getClients() . "\n";
echo "Bitrate: " . $stream->getBitrateKbps() . " Kbps\n";
}
} catch (SrsApiException $e) {
echo "Error: " . $e->getMessage() . "\n";
}
use SrsClient\Client;
use SrsClient\Config;
// Create configuration with credentials
$config = new Config('http://your-srs-server:1985', [
'credentials' => [
'username' => 'admin',
'password' => 'password'
],
'timeout' => 5,
'verify' => true,
'debug' => false
]);
// Initialize client
$client = new Client($config);
// Get SRS version
$version = $client->getVersions();
echo "Version: " . $version->getVersion() . "\n";
echo "Server ID: " . $version->getServerId() . "\n";
echo "Service ID: " . $version->getServiceId() . "\n";
// Check version
if ($version->isNewerThan('5.0.0')) {
echo "Running on newer version than 5.0.0\n";
}
// Working with streams
$streams = $client->getStreams();
$streamInfo = $client->getStream('stream-id');
$client->deleteStream('stream-id');
// Working with clients
$clients = $client->getClients(20); // get 20 clients
$clientInfo = $client->getClient('client-id');
$client->deleteClient('client-id');