A blazingly fast, zero-overhead HTTP kernel for PHP that compiles middleware stacks at boot time for maximum performance. Built with modern PHP features and designed for high-throughput applications.
Atomic HTTP Kernel delivers exceptional performance through compile-time optimization:
- 9M+ operations/sec - Kernel with no middleware
- 3M+ operations/sec - Kernel with middleware pipeline
- Zero runtime overhead - Middleware compilation happens once at boot
- Minimal memory footprint - Efficient object reuse and caching
Kernel Benchmark:
benchDirectHandler : 11,485,262 ops/sec
benchKernelNoMiddleware : 9,077,442 ops/sec (20% overhead)
benchKernelWithMiddleware : 3,122,516 ops/sec
benchCircuitBreakerKernel : 5,384,332 ops/sec
benchPerformanceKernel : 6,736,531 ops/sec
- Zero-Overhead Middleware - Compile middleware stacks once, execute millions of times
- PSR-7/PSR-15 Compatible - Full support for PSR HTTP standards
- Built-in Resilience - Circuit breaker and performance monitoring decorators
- Container Integration - Optional PSR-11 container support for dependency injection
- 100% Test Coverage - Comprehensive test suite with PHPUnit
- Built-in Benchmarking - Performance measurement tools included
- Type Safe - Strict types, readonly classes, and modern PHP 8.4+ features
composer require atomic/http-kernelRequirements:
- PHP 8.4 or higher
- PSR-7 HTTP Message implementation
- PSR-15 HTTP Server Request Handler interfaces
- PSR-7: HTTP message interfaces
- PSR-15: HTTP server request handlers and middleware
- PSR-11: Container interface (optional)
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Atomic\Http\Kernel;
use Atomic\Http\MiddlewareStack;
// Create your final request handler
$handler = new class implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface {
// Your application logic here
return new Response(200, [], 'Hello World!');
}
};
// Build middleware stack
$stack = new MiddlewareStack();
$stack->add(new AuthenticationMiddleware());
$stack->add(new LoggingMiddleware());
$stack->add(new CorsMiddleware());
// Create kernel (compilation happens here - once!)
$kernel = new Kernel($handler, $stack);
// Handle requests (zero overhead!)
$response = $kernel->handle($request);use Psr\Container\ContainerInterface;
$container = new YourContainer();
$stack = new MiddlewareStack($container);
// Add middleware by class name - resolved via container
$stack->add(AuthenticationMiddleware::class);
$stack->add(RateLimitingMiddleware::class);
$kernel = new Kernel($handler, $stack);use Atomic\Http\PerformanceKernel;
$performanceKernel = new PerformanceKernel(
kernel: $kernel,
metricsCallback: function (array $metrics): void {
// $metrics = ['duration_ms' => 1.23, 'status' => 200, 'method' => 'GET']
$logger->info('Request processed', $metrics);
}
);
$response = $performanceKernel->handle($request);use Atomic\Http\CircuitBreakerKernel;
$circuitBreaker = new CircuitBreakerKernel(
kernel: $kernel,
failureThreshold: 5, // Open after 5 failures
recoveryTimeout: 60.0 // Try again after 60 seconds
);
try {
$response = $circuitBreaker->handle($request);
} catch (RuntimeException $e) {
// Circuit breaker is open - service unavailable
$response = new Response(503, [], 'Service temporarily unavailable');
}┌─────────────────┐ ┌──────────────────┐ ┌─────────────────────┐
│ Kernel │───▶│ MiddlewareStack │───▶│ OptimizedMiddleware │
│ │ │ │ │ Handler │
│ Entry Point │ │ Compilation & │ │ │
│ Request Router │ │ Caching Logic │ │ Zero-overhead │
│ │ │ │ │ Execution Chain │
└─────────────────┘ └──────────────────┘ └─────────────────────┘
- Boot Time: Middleware stack compiles into optimized handler chain
- Runtime: Pre-compiled pipeline executes with zero overhead
- Caching: Compiled pipeline cached until middleware stack changes
// This happens ONCE at boot:
$compiledPipeline = $stack->compile($handler);
// This happens MILLIONS of times at runtime:
$response = $compiledPipeline->handle($request); // ⚡ Zero overhead!The main entry point for HTTP request processing.
final readonly class Kernel implements RequestHandlerInterface
{
public function __construct(
RequestHandlerInterface $handler,
MiddlewareStackInterface $stack
);
public function handle(ServerRequestInterface $request): ResponseInterface;
}Manages and compiles middleware into an optimized pipeline.
final class MiddlewareStack implements MiddlewareStackInterface
{
public function __construct(?ContainerInterface $container = null);
public function add(MiddlewareInterface|string $middleware): void;
public function compile(RequestHandlerInterface $handler): RequestHandlerInterface;
}Measures and reports request processing metrics.
final readonly class PerformanceKernel implements RequestHandlerInterface
{
public function __construct(
RequestHandlerInterface $kernel,
?Closure $metricsCallback = null
);
}Provides circuit breaker pattern for resilience.
final class CircuitBreakerKernel implements RequestHandlerInterface
{
public function __construct(
RequestHandlerInterface $kernel,
int $failureThreshold = 5,
float $recoveryTimeout = 60.0
);
public function getState(): string;
public function getFailureCount(): int;
public function getLastFailureTime(): ?float;
}Run the comprehensive test suite:
# Run all tests
composer test
# Run tests with coverage
composer test-coverage
# Run specific test suites
vendor/bin/phpunit tests/KernelTest.php
vendor/bin/phpunit tests/MiddlewareStackTest.php- Kernel: Request handling, compilation, error propagation
- MiddlewareStack: Compilation, caching, container integration
- Decorators: Performance monitoring, circuit breaker logic
- Edge Cases: Error handling, memory management, type safety
All tests pass with 100% code coverageMeasure performance with the built-in benchmark suite:
# Run all benchmarks
composer benchmark
# View detailed performance metrics
php benchmarks/run-benchmarks.phpKernel Benchmark:
benchDirectHandler : 11,485,262 ops/sec (0.000 ms/op)
benchKernelNoMiddleware : 9,077,442 ops/sec (0.000 ms/op)
benchKernelWithMiddleware : 3,122,516 ops/sec (0.000 ms/op)
benchCircuitBreakerKernel : 5,384,332 ops/sec (0.000 ms/op)
benchPerformanceKernel : 6,736,531 ops/sec (0.000 ms/op)
Middleware Stack Benchmark:
benchCompileEmptyStack : 10,326,182 ops/sec (0.000 ms/op)
benchCompileSmallStack : 10,176,773 ops/sec (0.000 ms/op)
benchCompileMediumStack : 10,164,141 ops/sec (0.000 ms/op)
benchCompileLargeStack : 10,398,357 ops/sec (0.000 ms/op)
Maintain code quality with included tools:
# Check code style
composer cs-check
# Fix code style
composer cs-fix
# Run static analysis
composer psalm
# Run all quality checks
composer qa| Framework/Library | Operations/sec | Notes |
|---|---|---|
| Atomic HTTP Kernel | 3,000,000+ | With middleware pipeline |
| ReactPHP | 500,000-1,000,000 | Async HTTP server |
| FastRoute | 100,000-500,000 | URL routing only |
| Symfony | 1,000-5,000 | Full-stack framework |
| Laravel | 500-2,000 | Full-stack framework |
Note: Benchmarks are approximate and depend on hardware, middleware complexity, and application logic. Atomic HTTP Kernel measurements represent operations per second for request handling, not full HTTP requests per second.
- Compile-time optimization over runtime flexibility
- Zero-overhead abstractions
- Minimal memory allocations
- Strict types throughout
- Readonly classes where immutability is desired
- Modern PHP 8.4+ features
- PSR-7: HTTP message interfaces
- PSR-11: Container interface (optional)
- PSR-15: HTTP server request handlers
- Single responsibility principle
- Dependency inversion
- Clean separation of concerns
We welcome contributions! Please see CONTRIBUTING.md for details.
# Clone repository
git clone https://github.com/atomic-php/http-kernel.git
cd http-kernel
# Install dependencies
composer install
# Run tests
composer test
# Run benchmarks
composer benchmark
# Check code quality
composer qa- Follow PSR-12 coding standards
- Add tests for new features
- Update benchmarks for performance-critical changes
- Maintain backwards compatibility
See CHANGELOG.md for release notes and version history.
This project is licensed under the MIT License - see the LICENSE file for details.
- Created by: Thavarshan ([email protected])
- Built on PSR standards by the PHP-FIG
- Inspired by modern HTTP processing patterns
- Performance techniques from the ReactPHP ecosystem
Built by Thavarshan for high-performance PHP applications
"An idiot admires complexity, a genius admires simplicity" - Terry A. Davis, Creator of Temple OS