feature #33698 [HttpKernel] compress files generated by the profiler (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] compress files generated by the profiler

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #33006
| License       | MIT
| Doc PR        | -

I've recently seen several reports of fastly growing profiler storages. Let's compress them when possible.

Locally for the skeleton homepage, a single profile goes from 150k to 15k. Level 3 is producing significant compression ratio while being measurably faster than level 6 (the default), that's why I'm using it.

Commits
-------

08f9470556 [HttpKernel] compress files generated by the profiler
This commit is contained in:
Fabien Potencier 2019-09-25 20:41:47 +02:00
commit 89d7931fdf

View File

@ -119,6 +119,10 @@ class FileProfilerStorage implements ProfilerStorageInterface
return null;
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
}
@ -161,7 +165,14 @@ class FileProfilerStorage implements ProfilerStorageInterface
'status_code' => $profile->getStatusCode(),
];
if (false === file_put_contents($file, serialize($data))) {
$context = stream_context_create();
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
stream_context_set_option($context, 'zlib', 'level', 3);
}
if (false === file_put_contents($file, serialize($data), 0, $context)) {
return false;
}
@ -282,6 +293,10 @@ class FileProfilerStorage implements ProfilerStorageInterface
continue;
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
$profile->addChild($this->createProfileFromData($token, unserialize(file_get_contents($file)), $profile));
}