Skip to content

Keep redirect chains out of the session and use the framework session API - #45

Merged
techmahedy merged 2 commits into
doppar:4.xfrom
techmahedy:feat/lazy-session-stores
Nov 4, 2026
Merged

techmahedy merged 2 commits into
doppar:4.xfrom
techmahedy:feat/lazy-session-stores

Conversation

@techmahedy

Copy link
Copy Markdown
Member

Summary

Insight read and wrote $_SESSION directly and called session_start(). That stops working once the framework session is no longer backed by PHP's native session, and the redirect chain it stored could not fit in a cookie-based session.

Problem

  1. SessionCollector, ProfilerMiddleware, and Profiler accessed $_SESSION and session_start() directly.
  2. On every redirect, the full profile of the request (queries, logs, timings) was stored in the session. With the cookie driver, whose limit is about 4 KB, a request that issued a few dozen queries and then redirected caused a SessionException.

What changed

  • All session access goes through $request->session(). This also works with earlier framework versions.
  • The session now holds only the request IDs of the redirects, capped at the last 10.
  • Profiler::getRedirectChain() resolves those IDs from Insight's own storage, where every profile is already persisted.
    • The chain nested inside each stored hop is stripped, so it is not duplicated.
    • IDs that are no longer in storage are skipped.
    • Entries written by the previous format still work.
  • The toolbar still shows the SQL queries of redirected requests.

@techmahedy
techmahedy requested a review from rrr63 November 2, 2026 10:03
Comment on lines -28 to 33
if (isset($_SESSION)) {
$sessionData = $_SESSION;
unset($sessionData['password'], $sessionData['_token']);
$sanitizer = $this->sanitizer();
$this->data['session_data'] = $sanitizer->sanitize($sessionData);
}
$sessionData = $request->session()->all();
unset($sessionData['password'], $sessionData['_token']);

$sanitizer = $this->sanitizer();
$this->data['session_data'] = $sanitizer->sanitize($sessionData);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on SessionCollector::start() the old isset($_SESSION) guard was dropped — if no session was ever started, the fallback Session binds &$_SESSION (null) and all() array shouldthrows an error ? that is a case we should still guard against (e.g. try/catch)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@techmahedy techmahedy Nov 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrr63 done, please check and good catch

@techmahedy
techmahedy merged commit b12cf29 into doppar:4.x Nov 4, 2026
3 checks passed
@rrr63

rrr63 commented Nov 4, 2026

Copy link
Copy Markdown
Member

thank you @techmahedy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants