-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: FrankenPHP Worker Mode #9889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.7
Are you sure you want to change the base?
Conversation
paulbalandan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to read up on this, but sharing initial comments.
neznaika0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't fully appreciate PR - I've never tried frankenphp. I'll probably come back to this later.
After accepting the PR, you can contact the developers and add CI4 to the list of available frameworks in the Native support for section. It would be a bit of a boost and a reminder of CI4.
| /** | ||
| * Checks if a service instance has been created. | ||
| * | ||
| * @param string $key Identifier of the entry to check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these important comments? Or rename the $key > $serviceName would be clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $key is used throughout this class, including in other methods. The comments are applied for consistency with the other methods, so I think we're fine.
|
I apply PR as patch for v4.7. phpstan have errors: [ErrorException]
Class CodeIgniter\Cache\ReconnectCacheDecorator contains 1 abstract method and must therefore be declared abstract or implement the remaining method
(CodeIgniter\Cache\CacheInterface::remember)
at SYSTEMPATH/Cache/ReconnectCacheDecorator.php:24 |
I think something may have gone wrong when you applied the patch, because the final code no longer contains |
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
apply code suggestion Co-authored-by: neznaika0 <ozornick.ks@gmail.com>
paulbalandan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great feature! I have read on the FrankenPHP's docs. Adding here some comments and I think this is good to go.
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
Description
This PR adds experimental support for FrankenPHP Worker Mode, allowing to handle multiple HTTP requests within the same PHP process. Instead of bootstrapping the framework for every request (traditional PHP-FPM model), the worker boots once and reuses resources across requests, resulting in 2-3x performance improvements for typical database-driven applications.
How it works
New features
app/Config/WorkerMode.php- Configuration for persistent services and garbage collectionphp spark worker:install- Generates Caddyfile and worker entry pointphp spark worker:uninstall- Removes worker mode filesOptimizations
Database:
BaseConnection::ping()method for connection health checkspg_ping(), other drivers useSELECT 1DatabaseConfig::validateForWorkerMode()- validates connections at request startDatabaseConfig::cleanupForWorkerMode()- detects uncommitted transactions and rolls backSession handlers:
PersistsConnectiontrait for Redis and Memcached handlersServices and state management:
Boot::bootWorker()- one-time initialization for worker modeCodeIgniter::resetForWorkerMode()- resets request-specific stateServices::resetForWorkerMode()- resets non-persistent services between requestsServices::validateForWorkerMode()- validates cache connectionsEvents::cleanupForWorkerMode()- clears event performance dataDebug Toolbar:
Toolbar::reset()- resets collectors between requests (development only)No impact on traditional PHP-FPM
All worker mode methods are only called from the worker entry point (
public/frankenphp-worker.php). When running in traditional PHP-FPM mode viapublic/index.php, none of this code is executed. The changes introduce zero performance overhead for applications not using worker mode.Benchmarks
I also prepared a set of simple benchmarks to evaluate worker mode performance: https://github.com/michalsn/benchmark-codeigniter-frankenphp
Based on existing benchmarks, nginx with PHP-FPM should perform similarly to FrankenPHP running in classic mode. When I attempted to verify this, the results showed roughly 60% of classic mode performance. However, these tests were run in a local development environment that is not properly tuned, which likely skewed the results.
For this reason, I decided not to include the benchmark numbers for nginx with PHP-FPM. In a real-world, properly configured environment, nginx is expected to perform similarly to FrankenPHP in classic mode.
Checklist: