-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Runtime] Automatically use FrankenPHP runner when its worker mode is detected #60503
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: 7.3
Are you sure you want to change the base?
Conversation
41b4f54
to
5a1bd6e
Compare
5a1bd6e
to
1be5a66
Compare
1be5a66
to
f7b1310
Compare
if (\extension_loaded('xdebug') && \function_exists('xdebug_connect_to_client')) { | ||
xdebug_connect_to_client(); | ||
} |
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.
For the record, this feature is currently broken in Xdebug. We're investigating what's going on. It doesn't hurt to keep this code anyway.
@@ -143,12 +147,23 @@ public function __construct(array $options = []) | |||
|
|||
$options['error_handler'] ??= SymfonyErrorHandler::class; | |||
|
|||
$workerLoopMax = $options['worker_loop_max'] ?? $_SERVER['FRANKENPHP_LOOP_MAX'] ?? $_ENV['FRANKENPHP_LOOP_MAX'] ?? null; |
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.
Shouldn't the env var has the same name as the option?
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 kept as is to keep the backward compatibility with the current runtime package, but maybe it's the occasion to have a better name indeed.
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.
It'd say we can keep FRANKENPHP_LOOP_MAP to help transitioning.
We also have the $_SERVER['APP_RUNTIME_OPTIONS']
vars which allows configuring any options.
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.
Wouldn't that require a modification in FrankenPHP itself?
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.
If it requires an update, we could make FrankenPHP compatible with both FRANKENPHP_LOOP_MAX
and (something like) WORKER_LOOP_MAX
, then deprecated the first one day when we're ready
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.
No need to modify FrankenPHP, this option is entirely handled by the runtime.
@@ -143,12 +147,23 @@ public function __construct(array $options = []) | |||
|
|||
$options['error_handler'] ??= SymfonyErrorHandler::class; | |||
|
|||
$workerLoopMax = $options['worker_loop_max'] ?? $_SERVER['FRANKENPHP_LOOP_MAX'] ?? $_ENV['FRANKENPHP_LOOP_MAX'] ?? null; | |||
if (null !== $workerLoopMax && (!\is_numeric($workerLoopMax) || $workerLoopMax <= 0)) { |
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.
filter_var
?
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.
If we do this (for example filter_var($options['worker_loop_max'] ?? $_SERVER['FRANKENPHP_LOOP_MAX'] ?? $_ENV['FRANKENPHP_LOOP_MAX'] ?? null, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
), we cannot detect if the option is a string like "foo", and it'll fallback on the default value. It works, but there will be no explicit error message to warn the user. Maybe I'm missing an argument to provide to filter_var?
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 code has -1 === $this->loopMax
so this check is not correct.
BTW, I'd suggest turning this into 0 >= $this->loopMax
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.
You can check the value of $workerLoopMax
before calling filter_var
. If $workerLoopMax !== null
and filter_var($workerLoopMax) === null
, then you know it is invalid.
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.
Indeed, I misunderstood the meaning of using -1
/0
. I updated accordingly and added a comment about negative values in the options array shape
@@ -143,12 +147,23 @@ public function __construct(array $options = []) | |||
|
|||
$options['error_handler'] ??= SymfonyErrorHandler::class; | |||
|
|||
$workerLoopMax = $options['worker_loop_max'] ?? $_SERVER['FRANKENPHP_LOOP_MAX'] ?? $_ENV['FRANKENPHP_LOOP_MAX'] ?? null; |
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.
It'd say we can keep FRANKENPHP_LOOP_MAP to help transitioning.
We also have the $_SERVER['APP_RUNTIME_OPTIONS']
vars which allows configuring any options.
f7b1310
to
fbf64c4
Compare
$this->kernel->terminate($sfRequest, $sfResponse); | ||
} | ||
|
||
gc_collect_cycles(); |
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'm wondering about this: could it become a perf hog?
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.
Maybe could we make this configurable (ex: run it after N requests), but this prevents the GC to be triggered in the middle of the handling of a request.
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.
Worker mode is relatively new to PHP so maybe there's something to improve on this topic in php-src itself?
Some new conditional trigger that'd be light to check when running the GC would be really useful?
Or maybe we can build something on gc_status?
If we want to give more control over this to end users, we could move the call into a kernel-terminate listener, that'd do it only in worker mode.
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.
It would be nice to move this logic to a listener and make it configurable, but maybe it could be done in a follow-up PR?
fbf64c4
to
5eac909
Compare
5eac909
to
5ce19ae
Compare
Currently, to use FrankenPHP worker mode, you have to install the
runtime/frankenphp-symfony
package and set theAPP_RUNTIME
env var to the correct FQCN.@dunglas and I would like to move the runtime and the runner classes to the Symfony core now that The PHP Foundation officially supports FrakenPHP.
This PR adds FrankenPHP worker mode detection and registers the correct runner to use it. This specific runner is only used when using the worker mode. When using FrankenPHP in classic mode,
HttpKernelRunner
is still used.The DX would be greatly improved, given that it works out of the box with this PR.
Classes and tests are coming from this repo with a few tweaks to stick to Symfony CS.