-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Labels
Description
Laravel Version
11.35.1
PHP Version
8.3.8
Database Driver & Version
MySql 8
Description
Multiple calls within while (true) loop to Cache::get() is causing incremental memory consumption (leak) when called from a custom artisan command ran within the terminal. See attached screenshots:
I'm using Redis as my cache driver locally here and in production. I'm using Laravel telescope locally.
Without the Cache::get block
/**
* Execute the console command.
*/
public function handle(): int
{
$lastRestart = Cache::get('statistic_aggregates:ingest:restart');
while (true) {
dump(memory_get_usage() / (1024 * 1024));
// if ($lastRestart !== Cache::get('statistic_aggregates:ingest:restart')) {
// Cache::forget('statistic_aggregates:ingest:restart');
// return self::SUCCESS;
// }
Sleep::for(1)->second();
}
}With the Cache::get block
/**
* Execute the console command.
*/
public function handle(): int
{
$lastRestart = Cache::get('statistic_aggregates:ingest:restart');
while (true) {
dump(memory_get_usage() / (1024 * 1024));
if ($lastRestart !== Cache::get('statistic_aggregates:ingest:restart')) {
Cache::forget('statistic_aggregates:ingest:restart');
return self::SUCCESS;
}
Sleep::for(1)->second();
}
}Steps To Reproduce
- Create a simple artisan command and run it from the command line with a while loop to Redis
Additionally, I have tried adding the following block of code to my project and calling it:
/**
* Schedule Telescope to store entries if enabled.
*/
protected function ensureTelescopeEntriesAreCollected(): void
{
if ($this->laravel->bound(\Laravel\Telescope\Contracts\EntriesRepository::class)) {
\Laravel\Telescope\Telescope::store($this->laravel->make(\Laravel\Telescope\Contracts\EntriesRepository::class));
}
}Still creating a memory leak after 10 seconds.
Additional context
I've just tried some other things, replacing dump() with echo, still get the same memory leak.
Interestingly the problem doesn't happen when simply echoing other facades like: str()->random(32) or now()

