1818use Micro \Kernel \App \Business \Event \ApplicationReadyEvent ;
1919use Micro \Kernel \App \Business \Event \ApplicationReadyEventInterface ;
2020use Micro \Plugin \Http \Facade \HttpFacadeInterface ;
21+ use Micro \Plugin \Http \Facade \HttpRoadrunnerFacadeInterface ;
2122use Nyholm \Psr7 \Factory \Psr17Factory ;
2223use Spiral \RoadRunner ;
2324use Symfony \Bridge \PsrHttpMessage \Factory \HttpFoundationFactory ;
2627final readonly class ApplicationRoadrunnerStartedListener implements EventListenerInterface
2728{
2829 public function __construct (
29- private HttpFacadeInterface $ httpFacade
30+ private HttpFacadeInterface $ httpFacade ,
31+ private HttpRoadrunnerFacadeInterface $ httpRoadrunnerFacade
3032 ) {
3133 }
3234
@@ -50,13 +52,19 @@ public function on(EventInterface $event): void
5052
5153 $ worker = RoadRunner \Worker::create ();
5254 $ worker = new RoadRunner \Http \PSR7Worker ($ worker , $ psr17Factory , $ psr17Factory , $ psr17Factory );
55+ $ i = 0 ;
56+ $ gcCollectStep = $ this ->httpRoadrunnerFacade ->getGcCollectCyclesCount ();
5357 while ($ request = $ worker ->waitRequest ()) {
5458 try {
5559 $ appRequest = $ httpFoundationFactory ->createRequest ($ request );
5660 $ appResponse = $ this ->httpFacade ->execute ($ appRequest , false );
5761 $ worker ->respond ($ httpMessageFactory ->createResponse ($ appResponse ));
5862 } catch (\Throwable $ e ) {
5963 $ worker ->getWorker ()->error ((string ) $ e );
64+ } finally {
65+ if (++$ i === $ gcCollectStep ) {
66+ gc_collect_cycles ();
67+ }
6068 }
6169 }
6270 }
0 commit comments