Skip to content

Commit

Permalink
frankenphp-symfony: call gc_collect_cycles() after handling request (#…
Browse files Browse the repository at this point in the history
…142)

Triggering the garbage collector after the request has been handled and
when the worker may be idle prevents the garbage collection from being
randomly done in the middle of the handling of a request (which delays
the delivery of the HTTP response).

Another option, that is done by Laravel Octone, is to trigger the GC
when a configurable amount of memory has been consumed instead of after
every request.
I think this patch is good enough for FrankenPHP as usually many workers
will be available.
  • Loading branch information
dunglas authored Oct 30, 2023
1 parent b5f4e09 commit da7093d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/frankenphp-symfony/src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
class Runner implements RunnerInterface
{
private HttpKernelInterface $kernel;

public function __construct(HttpKernelInterface $kernel)
public function __construct(private HttpKernelInterface $kernel)
{
$this->kernel = $kernel;
}

public function run(): int
Expand All @@ -40,6 +37,8 @@ public function run(): int
if ($this->kernel instanceof TerminableInterface && $sfRequest && $sfResponse) {
$this->kernel->terminate($sfRequest, $sfResponse);
}

gc_collect_cycles();
} while ($ret);

return 0;
Expand Down

0 comments on commit da7093d

Please sign in to comment.