Skip to content

Commit

Permalink
feature #33698 [HttpKernel] compress files generated by the profiler …
Browse files Browse the repository at this point in the history
…(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 89d7931
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 89d7931

Please sign in to comment.