Skip to content

Commit 89d7931

Browse files
committed
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
2 parents e2e73ef + 08f9470 commit 89d7931

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public function read($token): ?Profile
119119
return null;
120120
}
121121

122+
if (\function_exists('gzcompress')) {
123+
$file = 'compress.zlib://'.$file;
124+
}
125+
122126
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
123127
}
124128

@@ -161,7 +165,14 @@ public function write(Profile $profile): bool
161165
'status_code' => $profile->getStatusCode(),
162166
];
163167

164-
if (false === file_put_contents($file, serialize($data))) {
168+
$context = stream_context_create();
169+
170+
if (\function_exists('gzcompress')) {
171+
$file = 'compress.zlib://'.$file;
172+
stream_context_set_option($context, 'zlib', 'level', 3);
173+
}
174+
175+
if (false === file_put_contents($file, serialize($data), 0, $context)) {
165176
return false;
166177
}
167178

@@ -282,6 +293,10 @@ protected function createProfileFromData($token, $data, $parent = null)
282293
continue;
283294
}
284295

296+
if (\function_exists('gzcompress')) {
297+
$file = 'compress.zlib://'.$file;
298+
}
299+
285300
$profile->addChild($this->createProfileFromData($token, unserialize(file_get_contents($file)), $profile));
286301
}
287302

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy