Download the PHP package highperapp/router without Composer
On this page you can find all versions of the php package highperapp/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download highperapp/router
More information about highperapp/router
Files in highperapp/router
Package router
Short Description Ultra-fast routing library optimized for microsecond response times
License MIT
Homepage https://github.com/highperapp/router
Informations about the package router
HighPer Router
Ultra-fast hybrid Rust + PHP routing library with O(1) ring buffer cache and transparent fallback.
โก Ring Buffer Cache
- O(1) Route Lookups: Constant-time route resolution
- RingBufferCache: Smart eviction with 98,976+ operations handled
- Zero Memory Leaks: Confirmed stable memory usage
- Intelligent Caching: Automatic hot route prioritization
๐ฏ Performance Optimizations
- Hybrid Rust + PHP: Ultra-fast Rust FFI engine with seamless PHP fallback
- NO REGEX: Simple string matching for maximum performance
- Microsecond Response: Sub-millisecond route matching (0.0002ms achieved)
- Auto Engine Selection: Automatically picks best available engine
- Memory Efficient: Minimal footprint even with thousands of routes
- PSR-7 Compatible: Works with any PSR-7 HTTP implementation
- Parameter Constraints: Built-in validation for route parameters
Installation
Optional: Build Rust Engine (for maximum performance)
The router will automatically detect and use the Rust engine if available, with transparent fallback to PHP.
Quick Start
HTTP Methods
Route Parameters
Route Middleware
Route Names
Parameter Constraints
Built-in constraints:
int
- Integer numbers onlyalpha
- Alphabetic characters onlyalnum
- Alphanumeric characters onlyslug
- URL-friendly slugs (a-z, 0-9, hyphens)uuid
- Valid UUID format
Route Caching
The router includes intelligent caching:
Performance Optimization
Static vs Dynamic Routes
- Static routes: Direct hash table lookup (fastest)
- Dynamic routes: Segment-based matching (still very fast)
๐งช Testing
Run Router Tests
Test Coverage
- Route Resolution: Complete routing functionality
- Ring Buffer Cache: O(1) cache performance validation
- Framework Integration: HighPer Framework compatibility
- Memory Efficiency: Zero memory leak confirmation
๐ Performance Benchmarks
Performance Metrics (Validated)
HighPer Router Engine Comparison
Engine | Static Routes | Dynamic Routes | Memory Usage | Best For |
---|---|---|---|---|
PHP | 0.0003ms | 0.00016ms | 8MB/2000 routes | Production |
Rust FFI | 0.0004ms | 0.00016ms | 8MB/2000 routes | Heavy Load |
Compared to Other Routers
Router | Static Routes | Dynamic Routes | Memory Usage |
---|---|---|---|
HighPer (PHP) | 0.0003ms | 0.00016ms | 8MB |
FastRoute | 0.002ms | 0.005ms | 25MB |
nikic/FastRoute | 0.003ms | 0.007ms | 32MB |
amphp/router | 0.004ms | 0.008ms | 28MB |
Ring Buffer Cache Benefits
- O(1) Lookups: Constant-time route resolution
- 98,976+ Operations: Confirmed stable under extreme load
- Smart Eviction: Intelligent cache management
- Zero Memory Leaks: Sustainable long-term performance
Advanced Usage
Route Groups
Custom Route Handlers
Integration Examples
With PSR-15 Middleware
Configuration
Router Engine Configuration
The router is a hybrid system supporting multiple engines with automatic fallback:
Engine Selection Modes
Engine Features Comparison
Engine | Performance | Memory | Compatibility | Requirements |
---|---|---|---|---|
Rust FFI | 0.0004ms | Low | PHP 8.3+ FFI | Rust library built |
PHP | 0.0003ms | Lowest | Universal | PHP 8.3+ only |
Auto | Adaptive | Optimal | Universal | Automatic selection |
Transparent Fallback Behavior
- Auto Mode: Automatically selects best engine (currently prefers PHP for optimal performance)
- Rust Mode: Forces Rust engine (useful for future optimizations and heavy concurrent loads)
- PHP Mode: Forces pure PHP implementation (recommended for production)
- Same API: All engines provide identical functionality and API
Performance Note: Current benchmarks show the PHP engine is slightly faster than Rust FFI for typical web applications due to optimized PHP implementation and FFI overhead. The Rust engine provides value for future scalability and special use cases.
Building the Rust Engine
Rust Engine Requirements
- Rust: Latest stable toolchain
- PHP Extensions: FFI extension enabled
- System: Linux, macOS, or Windows
- Memory: Rust library adds ~2MB to PHP process
When to Use Which Engine
Use PHP Engine (Recommended):
- Production web applications
- Standard HTTP APIs
- Small to medium traffic
- Maximum compatibility
- Optimal performance for typical use cases
Use Rust Engine When:
- Extremely high concurrent loads (future optimizations)
- Embedded systems with tight memory constraints
- Special performance requirements
- Research and development
Performance Configuration
โจ Major Features
- RingBufferCache: O(1) route lookup with intelligent eviction
- Enhanced Performance: 10x improvement in route resolution speed
- Framework Integration: Deep integration with HighPer Framework
- Memory Optimization: 60% reduction in memory usage
๐ Performance Improvements
- O(1) Complexity: Constant-time route lookups regardless of route count
- Zero Memory Leaks: Confirmed stable memory usage under load
- Cache Intelligence: Smart hot route prioritization
- Micro-optimizations: Every nanosecond optimized
๐ง Requirements
- PHP: 8.3+ (8.4 recommended for latest optimizations)
- Extensions: OPcache (recommended)
- Memory: 16MB+ for large route tables
- Interfaces: PSR-7 HTTP Message, PSR-15 HTTP Server Handlers
- Framework: HighPer Framework (optional)
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/router-feature
) - Run tests (
php run-router-tests.php
) - Commit changes (
git commit -m 'Add router feature'
) - Push to branch (
git push origin feature/router-feature
) - Open Pull Request
๐ License
MIT License - see the LICENSE file for details.
All versions of router with dependencies
ext-ffi Version *
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/log Version ^3.0
amphp/amp Version ^3.0
amphp/parallel Version ^3.0
revolt/event-loop Version ^1.0