Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5dfb353

Browse filesBrowse files
committed
bug #47435 [HttpKernel] lock when writting profiles (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] lock when writting profiles | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47280 | License | MIT | Doc PR | - Commits ------- e65c54c [HttpKernel] lock when writting profiles
2 parents 8b76c95 + e65c54c commit 5dfb353
Copy full SHA for 5dfb353

File tree

1 file changed

+28
-28
lines changed
Filter options

1 file changed

+28
-28
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php
+28-28Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,7 @@ public function purge()
115115
*/
116116
public function read($token): ?Profile
117117
{
118-
if (!$token || !file_exists($file = $this->getFilename($token))) {
119-
return null;
120-
}
121-
122-
if (\function_exists('gzcompress')) {
123-
$file = 'compress.zlib://'.$file;
124-
}
125-
126-
if (!$data = unserialize(file_get_contents($file))) {
127-
return null;
128-
}
129-
130-
return $this->createProfileFromData($token, $data);
118+
return $this->doRead($token);
131119
}
132120

133121
/**
@@ -169,14 +157,13 @@ public function write(Profile $profile): bool
169157
'status_code' => $profile->getStatusCode(),
170158
];
171159

172-
$context = stream_context_create();
160+
$data = serialize($data);
173161

174-
if (\function_exists('gzcompress')) {
175-
$file = 'compress.zlib://'.$file;
176-
stream_context_set_option($context, 'zlib', 'level', 3);
162+
if (\function_exists('gzencode')) {
163+
$data = gzencode($data, 3);
177164
}
178165

179-
if (false === file_put_contents($file, serialize($data), 0, $context)) {
166+
if (false === file_put_contents($file, $data, \LOCK_EX)) {
180167
return false;
181168
}
182169

@@ -293,21 +280,34 @@ protected function createProfileFromData($token, $data, $parent = null)
293280
}
294281

295282
foreach ($data['children'] as $token) {
296-
if (!$token || !file_exists($file = $this->getFilename($token))) {
297-
continue;
283+
if (null !== $childProfile = $this->doRead($token, $profile)) {
284+
$profile->addChild($childProfile);
298285
}
286+
}
299287

300-
if (\function_exists('gzcompress')) {
301-
$file = 'compress.zlib://'.$file;
302-
}
288+
return $profile;
289+
}
303290

304-
if (!$childData = unserialize(file_get_contents($file))) {
305-
continue;
306-
}
291+
private function doRead($token, Profile $profile = null): ?Profile
292+
{
293+
if (!$token || !file_exists($file = $this->getFilename($token))) {
294+
return null;
295+
}
296+
297+
$h = fopen($file, 'r');
298+
flock($h, \LOCK_SH);
299+
$data = stream_get_contents($h);
300+
flock($h, \LOCK_UN);
301+
fclose($h);
307302

308-
$profile->addChild($this->createProfileFromData($token, $childData, $profile));
303+
if (\function_exists('gzdecode')) {
304+
$data = @gzdecode($data) ?: $data;
309305
}
310306

311-
return $profile;
307+
if (!$data = unserialize($data)) {
308+
return null;
309+
}
310+
311+
return $this->createProfileFromData($token, $data, $profile);
312312
}
313313
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.