tourze / srt-php
SRT (Secure Reliable Transport) protocol implementation in PHP
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tourze/srt-php
Requires
- ext-filter: *
- ext-hash: *
- ext-openssl: *
- ext-sockets: *
- ext-sodium: *
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-base: 1.*
This package is auto-updated.
Last update: 2025-12-20 18:21:27 UTC
README
π Pure PHP implementation of SRT (Secure Reliable Transport) protocol
π Table of Contents
- Overview
- Key Features
- Installation
- Quick Start
- Configuration
- Dependencies
- Architecture
- Advanced Usage
- Examples
- Testing
- Documentation
- Contributing
- License
π Overview
tourze/srt-php is a pure PHP implementation of the SRT protocol, providing low-latency,
high-reliability real-time data transmission capabilities for PHP developers.
π― Key Features
- β Secure Encryption: AES-128/192/256-CTR encryption support
- β Reliable Transport: Automatic Repeat reQuest (ARQ) mechanism
- β Low Latency: Live mode TSBPD support
- β Adaptive: Smart congestion control and flow management
- β High Performance: Precise RTT estimation and network condition assessment
Installation
composer require tourze/srt-php
Quick Start
Basic Usage
<?php use Tourze\SRT\Crypto\EncryptionManager; use Tourze\SRT\Live\TsbpdManager; use Tourze\SRT\Control\RttEstimator; // 1. Encryption functionality $encryption = new EncryptionManager( EncryptionManager::ALGO_AES_256, 'your_secret_passphrase' ); $encrypted = $encryption->encryptPacket($data, $sequenceNumber); $decrypted = $encryption->decryptPacket($encrypted, $sequenceNumber); // 2. Live mode TSBPD $tsbpd = new TsbpdManager(120); // 120ms playback delay $tsbpd->addPacket($data, $timestamp, $sequenceNumber); $readyPackets = $tsbpd->getReadyPackets(); // 3. RTT estimation $rttEstimator = new RttEstimator(); $rttEstimator->updateRtt($measuredRtt); $networkCondition = $rttEstimator->getNetworkCondition();
βοΈ Configuration
The package supports various configuration options for optimal performance:
Encryption Configuration
// Basic configuration $encryption = new EncryptionManager( EncryptionManager::ALGO_AES_256, // Algorithm 'your_secret_passphrase' // Passphrase ); // Advanced configuration with key rotation $keyManager = new KeyManager(); $keyManager->generateKey(256); $encryption->updateKey($keyManager->getKey());
TSBPD Configuration
// Configure playback delay and drift compensation $tsbpd = new TsbpdManager(120); $tsbpd->enableDriftCompensation(true); $tsbpd->setMaxDrift(10);
Dependencies
This package requires:
- PHP:
^8.1 - Extensions:
ext-filter: Data filtering and validationext-hash: Cryptographic hashing functionsext-openssl: SSL/TLS encryption supportext-sodium: Modern cryptographic library
π Architecture
src/
βββ Crypto/ π Encryption & Security Module
β βββ EncryptionManager.php
β βββ KeyManager.php
βββ Live/ β° Live Mode Features
β βββ TsbpdManager.php
βββ Control/ π Flow & Congestion Control
β βββ FlowControl.php
β βββ CongestionControl.php
β βββ RttEstimator.php
β βββ TimerManager.php
βββ Protocol/ π¦ Protocol Implementation
βββ Transport/ π Transport Layer
βββ Exception/ β οΈ Exception Handling
Advanced Usage
π Encryption & Security
use Tourze\SRT\Crypto\EncryptionManager; use Tourze\SRT\Crypto\KeyManager; // Advanced encryption setup $keyManager = new KeyManager(); $keyManager->generateKey(256); // Generate 256-bit key $encryption = new EncryptionManager( EncryptionManager::ALGO_AES_256, $keyManager->getKey() ); // Key rotation $keyManager->rotateKey(); $encryption->updateKey($keyManager->getKey());
π Flow Control & Congestion Management
use Tourze\SRT\Control\FlowControl; use Tourze\SRT\Control\CongestionControl; use Tourze\SRT\Control\RttEstimator; // Advanced flow control $flowControl = new FlowControl(100, 1000000); // Window size: 100, Rate: 1Mbps $congestionControl = new CongestionControl(); $rttEstimator = new RttEstimator(); // Adaptive rate control based on network conditions $networkCondition = $rttEstimator->getNetworkCondition(); $adaptiveRate = $congestionControl->calculateOptimalRate($networkCondition); $flowControl->updateSendingRate($adaptiveRate);
β° Time-Based Packet Delivery (TSBPD)
use Tourze\SRT\Live\TsbpdManager; // Advanced TSBPD configuration $tsbpd = new TsbpdManager(120); // 120ms playback delay // Configure drift compensation $tsbpd->enableDriftCompensation(true); $tsbpd->setMaxDrift(10); // 10ms maximum drift // Add packets with precise timing $tsbpd->addPacket($data, $timestamp, $sequenceNumber); // Get ready packets with statistics $readyPackets = $tsbpd->getReadyPackets(); $stats = $tsbpd->getStats();
π Phase 3 Complete Features
π Encryption & Security Module
- EncryptionManager: Support for AES-128/192/256-CTR encryption
- KeyManager: Key generation, storage, rotation, and exchange
- Support for PBKDF2 and HKDF key derivation
- Automatic key update mechanism
- Key strength validation and entropy detection
π Advanced Flow Control
- RttEstimator: RFC 6298 standard RTT estimation
- Network jitter detection and stability scoring
- Adaptive window size recommendations
- Intelligent network condition assessment (excellent/good/fair/poor/terrible)
- BDP (Bandwidth-Delay Product) calculation
β° Live Mode TSBPD
- TsbpdManager: Timestamp-based packet delivery
- Precise playback delay control (default 120ms)
- Automatic clock drift compensation
- Intelligent late packet dropping
- Real-time latency statistics and monitoring
π Performance Enhancements
- Improved congestion control algorithm integration
- Precise RTO calculation
- Network condition adaptive adjustment
- Comprehensive statistics and monitoring system
π§ͺ Examples
Run Basic Demo
cd packages/srt-php
php examples/basic_usage.php
Run Phase 3 Advanced Demo
cd packages/srt-php
php examples/phase3_demo.php
π§ͺ Testing
./vendor/bin/phpunit packages/srt-php/tests/
π Development Progress
| Version | Feature Scope | Status |
|---|---|---|
| v0.1.0 | Basic UDP + Simple Handshake | β Complete |
| v0.2.0 | Data Transfer + ACK/NAK | β Complete |
| v0.3.0 | Encryption + Flow Control + Live Mode | β Complete |
| v0.4.0 | Performance Optimization | π‘ Planned |
| v1.0.0 | Production Ready | π‘ Planned |
π― Performance Metrics
- β Latency: <120ms (Live mode)
- β Throughput: >10Mbps
- β Reliability: 99.9% packet transmission success rate
- β Security: AES-256 encryption protection
π Documentation
- Development Plan - Detailed development planning and progress
- API Documentation - Complete API reference
- Example Code - Usage examples and demonstrations
π€ Contributing
Contributions are welcome! Please follow these steps:
- Fork the project
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Create a Pull Request
License
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Related Links
Last updated: 2025-01-27
Current version: v0.3.0
Project status: π’ Phase 3 Advanced Features Complete