Skip to content

Commit 26a4356

Browse files
committed
Make sure sessions are cleaned after processing a request.
1 parent a607582 commit 26a4356

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Bridges/HttpKernel.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public function handle(ServerRequestInterface $request)
9595
// end buffering if we need to throw
9696
@ob_end_clean();
9797
return $response;
98+
} finally {
99+
$this->cleanUpSession();
98100
}
99101

100102
$out = ob_get_clean();
@@ -211,20 +213,6 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
211213
*/
212214
protected function mapResponse(SymfonyResponse $syResponse, $stdout='')
213215
{
214-
// end active session
215-
if (PHP_SESSION_ACTIVE === session_status()) {
216-
// make sure open session are saved to the storage
217-
// in case the framework hasn't closed it correctly.
218-
session_write_close();
219-
}
220-
221-
// reset session_id in any case to something not valid, for next request
222-
session_id('');
223-
224-
//reset $_SESSION
225-
session_unset();
226-
unset($_SESSION);
227-
228216
$nativeHeaders = [];
229217

230218
foreach (headers_list() as $header) {
@@ -338,4 +326,24 @@ protected function normalizeAppBootstrap($appBootstrap)
338326
}
339327
}
340328
}
329+
330+
protected function cleanUpSession()
331+
{
332+
// end active session
333+
if (PHP_SESSION_ACTIVE === session_status()) {
334+
// make sure open session are saved to the storage
335+
// in case the framework hasn't closed it correctly.
336+
try {
337+
session_write_close();
338+
} catch (\ErrorException $e) {
339+
}
340+
}
341+
342+
// reset session_id in any case to something not valid, for next request
343+
session_id('');
344+
345+
//reset $_SESSION
346+
session_unset();
347+
unset($_SESSION);
348+
}
341349
}

0 commit comments

Comments
 (0)