Replies: 1 comment
-
|
This is nice addition to nette, we are currently reworking our Nette RoadRunner extension, we have some MR to make our life less miserable about implementing... This proposal will make our life even less miserable, yet it is big shift and im not sure if it is backward compatible on Nette side :( |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Add Support for PHP Runtimes
Summary
This proposal suggests adding official support for long-running PHP runtimes (like Open Swoole, RoadRunner, and FrankenPHP) in Nette Framework through a runtime abstraction layer. This would bring significant performance improvements while maintaining backward compatibility and the elegant simplicity Nette is known for.
Table of Contents
Context: The Rise of PHP Runtimes
In recent years, we have seen a significant shift in how PHP applications are deployed. Modern PHP runtimes that keep applications in memory between requests are becoming increasingly popular, offering 5-10x performance improvements over traditional PHP-FPM deployments.
Traditional PHP-FPM Model:
Long-Running Runtime Model:
Performance Improvement: Typically 5-10x faster response times, significantly lower resource usage.
Current State in PHP Ecosystem
Symfony: Runtime Component
Symfony introduced the Runtime Component in version 5.3, providing a vendor-agnostic abstraction for different runtimes.
Architecture:
Key Design Principles:
Supported Runtimes:
runtime/swoole)runtime/roadrunner-symfony-nyholm)runtime/frankenphp)runtime/react-php)Laravel: Octane
Laravel introduced Octane in version 8.x, providing first-class runtime support with automatic state management.
Key Features:
State Management:
Octane automatically resets:
Other Frameworks
mezzio/mezzio-swooleComparsion of primitive application
Comparison of individual solutions, without booting Nette.
Starting the test via:
$ wrk -t10 -c1000 -d30s <host>Both applications only output simple JSON:
Nginx Unit
Open Swoole
Test Summary
Rough data (not a real application example) is 5.55k vs. 213 req/sec, so Open Swoole is ~25x faster.
For real UCs, the estimate is 8-12x faster depending on specific application.
The Challenge for Nette
While other major frameworks have embraced runtime support, Nette currently lacks official runtime integration. This creates several challenges:
1. Bootstrap Dependency on Global State
Current Nette bootstrapping in typical applications:
This pattern assumes:
$_SERVER,$_POST, etc.) available2. Stateful Services in DI Container
Nette's DI container creates singleton services by default. In a long-running process, this can lead to state leakage:
3. Session Handling
Standard
session_start()relies on PHP's built-in session mechanism, which assumes process lifecycle. Runtime environments handle sessions differently (via cookies bridging).4. Tracy Debugger
Tracy's global error handler and debug bar accumulate state that must be reset between requests.
5. Database Connections
Connection pooling vs. connection reset strategies need careful consideration in long-running processes.
Proposed Solution: Nette Runtime Component
I propose introducing a Nette Runtime Component inspired by Symfony's approach but tailored to Nette's philosophy and conventions.
Core Architecture
Lifecycle Hook System
Configuration (NEON)
Entry Point Modification
State Reset Strategy
The component would provide built-in hooks for common scenarios:
1. HTTP Objects (Fresh Per Request):
2. Database Connection (Validate & Reset):
3. Session (Cookie Bridge):
Implementation Phases
Phase 1: Core Abstraction (Foundation)
Deliverables:
Nette\Runtimenamespace with core interfacesTime Estimate: 6-8 weeks
Phase 2: Additional Runtimes (Expansion)
Deliverables:
Time Estimate: 4-6 weeks
Phase 3: Ecosystem Integration (Polish)
Deliverables:
Time Estimate: 2-4 weeks
Benefits for Nette Community
Real-World Performance Data
Based on community benchmarks (February 2024-2025):
These are average numbers for typical web applications. Results vary by application complexity.
Example: Simple Nette App with Runtime
Open Questions for Discussion
nette/runtimepackage?Conclusion
Long-running PHP runtimes are becoming the industry standard for high-performance applications. Adding official runtime support to Nette would:
I believe this is a natural evolution for Nette, similar to how the framework adapted to dependency injection, Composer, and other standards in the past. The key is implementing it in a way that feels "Nette-like" - simple, elegant, and opt-in.
I am happy to contribute to this effort and have already done extensive research on runtime integration patterns, state management strategies, and compatibility challenges specific to Nette's architecture.
Would the Nette team and community be interested in exploring this further?
References
Technical Diagrams
Request Flow Comparison
Traditional PHP-FPM:
Long-Running Runtime:
State Management Hierarchy
Type: Feature Proposal / RFC
Beta Was this translation helpful? Give feedback.
All reactions