highperapp/highper-php

High-performance asynchronous PHP micro framework targeting C10M concurrency with maximum simplicity and peak performance

1.0.4 2025-07-27 12:37 UTC

This package is auto-updated.

Last update: 2025-09-12 01:50:12 UTC


README

PHP Version Performance Concurrency Reliability Tests

Enterprise PHP framework designed for high-scale production applications.

๐Ÿš€ Quick Start

# Basic server
bin/highper serve

# Production with all optimizations  
bin/highper serve --workers=4 --c10m --rust=enabled --memory-limit=1G --zero-downtime

# Dedicated ports mode
bin/highper serve --mode=dedicated --http-port=8080 --ws-port=8081

๐Ÿ—๏ธ Hybrid Multi-Process + Async Architecture

Core Design: Combines process isolation with async I/O efficiency

  • Multi-process worker spawning using pcntl_fork()
  • RevoltPHP + UV hybrid event loop per worker
  • Zero-downtime deployments with blue-green/rolling strategies
  • C10M optimizations for 10 million concurrent connections
  • Rust FFI integration for performance-critical components

Advanced CLI Features

bin/highper help                    # Show all architecture options
bin/highper status                  # System capability check

# Architecture options
--workers=COUNT                     # Worker processes (auto-detect CPU cores)
--mode=single|dedicated             # Single port vs dedicated ports
--c10m                             # C10M optimizations  
--rust=enabled                     # Rust FFI performance boost
--zero-downtime                    # Zero-downtime deployments
--deployment-strategy=blue_green    # Deployment strategy
--memory-limit=SIZE                # Worker memory limit

๐Ÿ—๏ธ Architecture

Core Design Principles

  1. Interface-Driven: All contracts defined as interfaces (NO abstract classes)
  2. External Dependencies: Foundation components as external packages
  3. Service Providers: Package integration via auto-discovery
  4. Extension-Friendly: Everything extendable (NO final keywords)
  5. Rust FFI Enhancement: Strategic performance boosts where needed

Foundation Components

Foundation Dependencies:
โ”œโ”€โ”€ RevoltPHP/EventLoop           # Event loop foundation (C10M optimized)
โ”œโ”€โ”€ AMPHP v3 ecosystem            # Async/parallel infrastructure  
โ”œโ”€โ”€ amphp/http-server             # HTTP server foundation (C10M ready)
โ”œโ”€โ”€ amphp/parallel                # Multi-process support (scalability)
โ”œโ”€โ”€ highperapp/container          # External PSR-11 container
โ”œโ”€โ”€ highperapp/router             # External ultra-fast router (O(1) lookups)
โ”œโ”€โ”€ vlucas/phpdotenv              # Environment configuration
โ””โ”€โ”€ filp/whoops                   # Error & exception handling

๐Ÿ“ฆ Package Ecosystem

HighPer Framework supports 18+ standalone packages that can be used independently:

Foundation Packages (Required):

  • highperapp/container: PSR-11 container optimized for C10M
  • highperapp/router: Ultra-fast router with O(1) lookups + Rust FFI
  • highperapp/zero-downtime: Zero-downtime deployment system

Optional Standalone Libraries:

  • highperapp/cache: Multi-driver async caching with Redis/Memcached
  • highperapp/cli: Command-line interface framework
  • highperapp/crypto: Cryptographic operations with Rust FFI
  • highperapp/database: Async database with EventSourcing/CQRS
  • highperapp/grpc: gRPC server integration
  • highperapp/monitoring: Performance monitoring and metrics
  • highperapp/paseto: PASETO v4 tokens with Rust FFI
  • highperapp/realtime: Real-time communication protocols
  • highperapp/security: Security enhancements and validation
  • highperapp/spreadsheet: High-performance spreadsheet manipulation
  • highperapp/stream-processing: Stream processing capabilities
  • highperapp/tcp: TCP server and client implementations
  • highperapp/tracing: Distributed tracing and observability
  • highperapp/validator: Data validation with Rust FFI
  • highperapp/websockets: WebSocket streaming with backpressure

๐Ÿฆ€ Rust FFI Integration

Strategic Rust components provide massive performance gains:

  • Router: 10-50x improvement (O(1) radix tree vs PHP regex)
  • Crypto: 5-20x improvement (native operations vs PHP)
  • PASETO: 3-10x improvement (vs PHP JWT libraries)
  • Validator: 2-5x improvement (native regex + validation)

๐Ÿ“ Project Structure

/home/user/highperapp/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Contracts/                    # Framework interfaces (no abstract classes)
โ”‚   โ”‚   โ”œโ”€โ”€ ApplicationInterface.php
โ”‚   โ”‚   โ”œโ”€โ”€ ContainerInterface.php
โ”‚   โ”‚   โ”œโ”€โ”€ RouterInterface.php
โ”‚   โ”‚   โ”œโ”€โ”€ ConfigManagerInterface.php
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ Foundation/                   # Core implementations
โ”‚   โ”‚   โ”œโ”€โ”€ Application.php           # implements ApplicationInterface
โ”‚   โ”‚   โ”œโ”€โ”€ ConfigManager.php         # implements ConfigManagerInterface
โ”‚   โ”‚   โ”œโ”€โ”€ AsyncLogger.php           # implements LoggerInterface
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ ServiceProvider/              # Service provider system
โ”‚   โ”‚   โ”œโ”€โ”€ PackageDiscovery.php      # Auto-discover packages
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ composer.json                    # Foundation dependencies
โ””โ”€โ”€ README.md

๐Ÿš€ Quick Start

Installation

composer require highperapp/highper-php

Basic Usage

<?php

use HighPerApp\HighPer\Foundation\Application;

// Create application with auto-discovery
$app = new Application([
    'packages' => [
        'auto_discover' => true,     # Automatically load installed packages
        'websockets' => true,        # Enable WebSocket support
        'database' => true,          # Enable async database
        'cache' => true,             # Enable high-performance caching
    ]
]);

// Bootstrap and run
$app->bootstrap();
$app->run();

With Rust FFI Performance

# Build Rust components for maximum performance
cd packages/highper-router/rust && ./build.sh
cd packages/highper-crypto/rust && ./build.sh
cd packages/highper-paseto/rust && ./build.sh
cd packages/highper-validator/rust && ./build.sh

๐Ÿงช Comprehensive Testing

Professional test suite covering all architecture components:

# Run all tests
php run-tests.php

# Specific test suites  
php run-tests.php --suite=unit                    # Core components
php run-tests.php --suite=integration             # CLI and architecture
php run-tests.php --suite=performance             # C10M validation
php run-tests.php --suite=concurrency             # Multi-process safety

# System capability check
php run-tests.php --system-check

Test Coverage

  • Unit Tests: ProcessManager, HybridEventLoop, ArchitectureValidator
  • Integration Tests: CLI commands, multi-process architecture
  • Performance Tests: C10M optimizations, memory efficiency
  • Concurrency Tests: Thread safety, race condition prevention

๐Ÿ“ Key Implementation Files

src/Foundation/
โ”œโ”€โ”€ ProcessManager.php              # Multi-process worker management
โ”œโ”€โ”€ HybridEventLoop.php             # RevoltPHP + UV event loop  
โ”œโ”€โ”€ ArchitectureValidator.php       # Configuration validation
โ””โ”€โ”€ Application.php                 # Main application bootstrap

tests/
โ”œโ”€โ”€ Unit/                          # Component unit tests
โ”‚   โ”œโ”€โ”€ ProcessManagerTest.php
โ”‚   โ”œโ”€โ”€ HybridEventLoopTest.php  
โ”‚   โ””โ”€โ”€ ArchitectureValidatorTest.php
โ”œโ”€โ”€ Integration/                   # Integration tests
โ”‚   โ”œโ”€โ”€ MultiProcessArchitectureTest.php
โ”‚   โ””โ”€โ”€ CLIArchitectureTest.php
โ”œโ”€โ”€ Performance/                   # Performance validation
โ”‚   โ””โ”€โ”€ C10MArchitectureTest.php
โ””โ”€โ”€ Concurrency/                   # Concurrency safety
    โ””โ”€โ”€ MultiProcessConcurrencyTest.php

๐Ÿ”ง Requirements

  • PHP: 8.3+ with pcntl, posix extensions
  • Extensions:
    • Required: pcntl, posix (for multi-process architecture)
    • Recommended: ext-uv (15-25% performance boost), opcache, FFI (for Rust acceleration)
  • Memory: 256MB+ per worker
  • OS: Linux (recommended), macOS, Windows

Installing php-uv Extension (Recommended)

For optimal performance in high-concurrency scenarios, install the php-uv extension:

# Ubuntu/Debian
sudo apt-get install libuv1-dev
sudo pecl install uv

# CentOS/RHEL
sudo yum install libuv-devel
sudo pecl install uv

# macOS
brew install libuv
sudo pecl install uv

# Add to php.ini
echo "extension=uv" >> /etc/php/8.3/cli/php.ini

Performance Benefits with php-uv:

  • 15-25% performance boost in high-concurrency scenarios
  • 20-30% memory reduction in event loop operations
  • Improved I/O performance for file operations and network connections
  • Better timer precision and efficiency

๐Ÿ“ License

MIT License. See LICENSE file for details.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Built with โค๏ธ for C10M performance and maximum simplicity from Hyderabad, India.