Skip to content
Permalink
Browse files

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
-------

08f9470 [HttpKernel] compress files generated by the profiler
  • Loading branch information...
fabpot committed Sep 25, 2019
2 parents e2e73ef + 08f9470 commit 89d7931fdfcb9b9b3e0b72efc862bd7c07bf6057
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php
@@ -119,6 +119,10 @@ public function read($token): ?Profile
return null;
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
}
@@ -161,7 +165,14 @@ public function write(Profile $profile): bool
'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 @@ protected function createProfileFromData($token, $data, $parent = null)
continue;
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
$profile->addChild($this->createProfileFromData($token, unserialize(file_get_contents($file)), $profile));
}

0 comments on commit 89d7931

Please sign in to comment.
You can’t perform that action at this time.