sangezar / srs-php-client
PHP client for SRS (Simple Realtime Server) API
v1.0.1
2025-02-02 17:43 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
README
PHP client for interacting with SRS (Simple Realtime Server) API.
Features
- 🚀 Full SRS API support
- 🔧 Convenient object-oriented interface
- 📝 Typed data and IDE autocompletion
- 📚 Detailed documentation and examples
- 🛡️ Error handling and exceptions
- 🔒 SSL/TLS support
- ⚙️ Flexible configuration
Installation
composer require sangezar/srs-php-client
Quick Start
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"; }
Documentation
Detailed documentation is available in multiple languages in the docs directory:
Requirements
- PHP 7.4 or higher
- Composer
- PHP Extensions:
- JSON
- cURL
Testing
composer test
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
Support
If you encounter any issues or have suggestions for improvements, please:
- Check existing issues
- Create a new issue with a detailed description
- Submit a pull request with fixes or improvements
Changelog
All notable changes are documented in the CHANGELOG.md file.
Usage
Basic Usage
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');
Available Settings
Configuration supports the following options:
credentials
- Authentication credentials:username
- Usernamepassword
- Password
timeout
- Request timeout in seconds (default: 30)verify
- SSL certificate verification (true/false or path to CA bundle)proxy
- Proxy settingsdebug
- Debug mode (true/false)headers
- Additional HTTP headers
Available Methods
System Information
getVersions()
- Get SRS version- Returns
Version
object with methods:getVersion()
- Full version (e.g., "5.0.213")getServerId()
- Unique server IDgetServiceId()
- Unique service IDgetPid()
- Process IDgetMajor()
- Major versiongetMinor()
- Minor versiongetRevision()
- RevisionisVersion(string $version)
- Check specific versionisNewerThan(string $version)
- Check if version is newerisOlderThan(string $version)
- Check if version is older
- Returns
getSummaries()
- Get general information (pid, argv, pwd, cpu, mem)getRusages()
- Get resource usage statisticsgetSelfProcStats()
- Get SRS process statisticsgetSystemProcStats()
- Get system process statisticsgetMeminfos()
- Get system memory informationgetPerformance()
- Get system performance statistics
Server Information
getAuthors()
- Get information about authors, license, and contributorsgetFeatures()
- Get list of supported featuresgetRequests()
- Get current request informationgetRawConfig()
- Get RAW SRS configuration
Virtual Host Management
getVhosts()
- Get list of all virtual hostsgetVhost(string $vhost)
- Get information about specific virtual host
Stream Management
getStreams()
- Get list of all streamsgetStream(string $streamId)
- Get information about specific streamdeleteStream(string $streamId)
- Delete stream
Client Management
getClients(int $count = 10)
- Get list of clients (default 10)getClient(string $clientId)
- Get information about specific clientdeleteClient(string $clientId)
- Delete client
Cluster and Diagnostics
getClusters()
- Cluster managementgetTcmalloc(string $page = 'summary')
- Get tcmalloc information
Error Handling
use SrsClient\Exception\SrsApiException; try { $streams = $client->getStreams(); } catch (SrsApiException $e) { echo "Error: " . $e->getMessage(); }