Skip to content

Commit da7093d

Browse files
authored
frankenphp-symfony: call gc_collect_cycles() after handling request (#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.
1 parent b5f4e09 commit da7093d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/frankenphp-symfony/src/Runner.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
*/
1717
class Runner implements RunnerInterface
1818
{
19-
private HttpKernelInterface $kernel;
20-
21-
public function __construct(HttpKernelInterface $kernel)
19+
public function __construct(private HttpKernelInterface $kernel)
2220
{
23-
$this->kernel = $kernel;
2421
}
2522

2623
public function run(): int
@@ -40,6 +37,8 @@ public function run(): int
4037
if ($this->kernel instanceof TerminableInterface && $sfRequest && $sfResponse) {
4138
$this->kernel->terminate($sfRequest, $sfResponse);
4239
}
40+
41+
gc_collect_cycles();
4342
} while ($ret);
4443

4544
return 0;

0 commit comments

Comments
 (0)