定制 sangezar/srs-php-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sangezar/srs-php-client

最新稳定版本:v1.0.1

Composer 安装命令:

composer require sangezar/srs-php-client

包简介

PHP client for SRS (Simple Realtime Server) API

README 文档

README

PHP client for interacting with SRS (Simple Realtime Server) API.

Latest Version on Packagist Total Downloads Software License

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:

  1. Check existing issues
  2. Create a new issue with a detailed description
  3. 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 - Username
    • password - Password
  • timeout - Request timeout in seconds (default: 30)
  • verify - SSL certificate verification (true/false or path to CA bundle)
  • proxy - Proxy settings
  • debug - 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 ID
      • getServiceId() - Unique service ID
      • getPid() - Process ID
      • getMajor() - Major version
      • getMinor() - Minor version
      • getRevision() - Revision
      • isVersion(string $version) - Check specific version
      • isNewerThan(string $version) - Check if version is newer
      • isOlderThan(string $version) - Check if version is older
  • getSummaries() - Get general information (pid, argv, pwd, cpu, mem)
  • getRusages() - Get resource usage statistics
  • getSelfProcStats() - Get SRS process statistics
  • getSystemProcStats() - Get system process statistics
  • getMeminfos() - Get system memory information
  • getPerformance() - Get system performance statistics

Server Information

  • getAuthors() - Get information about authors, license, and contributors
  • getFeatures() - Get list of supported features
  • getRequests() - Get current request information
  • getRawConfig() - Get RAW SRS configuration

Virtual Host Management

  • getVhosts() - Get list of all virtual hosts
  • getVhost(string $vhost) - Get information about specific virtual host

Stream Management

  • getStreams() - Get list of all streams
  • getStream(string $streamId) - Get information about specific stream
  • deleteStream(string $streamId) - Delete stream

Client Management

  • getClients(int $count = 10) - Get list of clients (default 10)
  • getClient(string $clientId) - Get information about specific client
  • deleteClient(string $clientId) - Delete client

Cluster and Diagnostics

  • getClusters() - Cluster management
  • getTcmalloc(string $page = 'summary') - Get tcmalloc information

Error Handling

use SrsClient\Exception\SrsApiException;

try {
    $streams = $client->getStreams();
} catch (SrsApiException $e) {
    echo "Error: " . $e->getMessage();
}

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-02