Skip to content

Commit

Permalink
[HttpKernel] compress files generated by the profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 25, 2019
1 parent 373469b commit 08f9470
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 08f9470

Please sign in to comment.