Skip to content

Commit

Permalink
Fix memory leaks in Octane (#393)
Browse files Browse the repository at this point in the history
* fix memory leaks on octane

* Fix styling

* fix

* Fix styling

Co-authored-by: themsaid <[email protected]>
  • Loading branch information
themsaid and themsaid authored Jun 3, 2021
1 parent 106f1af commit e1a730f
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Engines\CompilerEngine as LaravelCompilerEngine;
use Illuminate\View\Engines\PhpEngine as LaravelPhpEngine;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\TaskReceived;
use Laravel\Octane\Events\TickReceived;
use Livewire\CompilerEngineForIgnition;
use Monolog\Logger;
use Throwable;
Expand Down Expand Up @@ -96,6 +99,10 @@ public function boot()
$this->setupQueue($this->app->get('queue'));
}

if (isset($_SERVER['LARAVEL_OCTANE'])) {
$this->setupOctane();
}

if (config('flare.reporting.report_logs')) {
$this->app->make(LogRecorder::class)->register();
}
Expand Down Expand Up @@ -458,20 +465,40 @@ protected function getConfigFileLocation(): ?string
return null;
}

protected function resetFlare()
{
$this->app->get(Flare::class)->reset();

if (config('flare.reporting.report_logs')) {
$this->app->make(LogRecorder::class)->reset();
}

if (config('flare.reporting.report_queries')) {
$this->app->make(QueryRecorder::class)->reset();
}

$this->app->make(DumpRecorder::class)->reset();
}

protected function setupQueue(QueueManager $queue)
{
$queue->looping(function () {
$this->app->get(Flare::class)->reset();
$this->resetFlare();
});
}

if (config('flare.reporting.report_logs')) {
$this->app->make(LogRecorder::class)->reset();
}
protected function setupOctane()
{
$this->app['events']->listen(RequestReceived::class, function () {
$this->resetFlare();
});

if (config('flare.reporting.report_queries')) {
$this->app->make(QueryRecorder::class)->reset();
}
$this->app['events']->listen(TaskReceived::class, function () {
$this->resetFlare();
});

$this->app->make(DumpRecorder::class)->reset();
$this->app['events']->listen(TickReceived::class, function () {
$this->resetFlare();
});
}
}

0 comments on commit e1a730f

Please sign in to comment.