Skip to content
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

frankenphp-symfony: perf improvement #148

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@
</file>
<file src="src/frankenphp-symfony/src/Runner.php">
<UndefinedFunction>
<code><![CDATA[\frankenphp_handle_request(function () use ($server, &$sfRequest, &$sfResponse): void {
// Merge the environment variables coming from DotEnv with the ones tight to the current request
$_SERVER += $server;

$sfRequest = Request::createFromGlobals();
$sfResponse = $this->kernel->handle($sfRequest);

$sfResponse->send();
})]]></code>
<code><![CDATA[\frankenphp_handle_request($handler)]]></code>
</UndefinedFunction>
</file>
<file src="src/google-cloud/router.php">
Expand Down
23 changes: 13 additions & 10 deletions src/frankenphp-symfony/src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@ public function __construct(private HttpKernelInterface $kernel)

public function run(): int
{
$kernel = $this->kernel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, static function might not be worth it here since it has a reason to use $this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I was hesitating but let's keep this simple indeed.

$server = array_filter($_SERVER, static fn (string $key) => !str_starts_with($key, 'HTTP_'), ARRAY_FILTER_USE_KEY);
$server['APP_RUNTIME_MODE'] = 'web=1&worker=1';

do {
$ret = \frankenphp_handle_request(function () use ($server, &$sfRequest, &$sfResponse): void {
// Merge the environment variables coming from DotEnv with the ones tight to the current request
$_SERVER += $server;
$handler = static function () use ($kernel, $server, &$sfRequest, &$sfResponse): void {
// Merge the environment variables coming from DotEnv with the ones tied to the current request
$_SERVER += $server;

$sfRequest = Request::createFromGlobals();
$sfResponse = $kernel->handle($sfRequest);

$sfRequest = Request::createFromGlobals();
$sfResponse = $this->kernel->handle($sfRequest);
$sfResponse->send();
};

$sfResponse->send();
});
do {
$ret = \frankenphp_handle_request($handler);

if ($this->kernel instanceof TerminableInterface && $sfRequest && $sfResponse) {
$this->kernel->terminate($sfRequest, $sfResponse);
if ($kernel instanceof TerminableInterface && $sfRequest && $sfResponse) {
$kernel->terminate($sfRequest, $sfResponse);
}

gc_collect_cycles();
Expand Down
Loading