Answers.Body: <p>I'm not sure there is going to be an easy way to do this in Craft 2, unfortunately.</p>
  
  <p>In the upcoming Craft 3, we refactored the session logic so that a session will only get started on requests that actually <em>need</em> session, which is basically what you're looking for.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-14T19:19:11.207Z
Answers.Text: Excellent. As an side, this is going to make full page caching a lot easier from the server side.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T22:31:19.890Z
Answers.LastActivityDate: 2017-01-12T22:31:19.890Z
Answers.UserDisplayName: Brad Bell
Body: <p>We're running a craftcms-backed site that uses sessions only for the admin pages.</p>
  
  <p>For a few reasons, we'd like to disable session logic for all other urls:</p>
  
  <ul>
  <li>the <code>Set-Cookie</code> header that craft uses to initiate a session makes responses uncacheable in our fronting cache layers</li>
  <li>the code path under <code>Craft\UserSessionService</code> is unnecessary overhead for most of our logic, and occasionally adds considerable latency</li>
  </ul>
  
  <p>We've been using <code>HeaderHelper::removeHeader('Set-Cookie');</code> on a per-controller basis to turn off this behavior, but that only gets us so far - for example, <code>404</code> responses seem to try to initiate user sessions as well, before any of our custom logic can be used:</p>
  
  <p><a href="https://i.sstatic.net/7azls.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7azls.png" alt="This is a screenshot of newrelic transaction trace for a 404 response"></a>
  (This is a screenshot of newrelic transaction trace for a 404 response)</p>
  
  <p>How can we get craftcms to stop trying to set these sessions?</p>
  
  <p>I should note that we're looking into getting session storage out of the filesystem and into redis, which should also help - but most of the sessions we're keeping are meaningless, and I'd rather not keep track of them at all.</p>
  
Tags: <config><session><cookies>
Title: How can I disable sessions for most of my Craft site?
ThreadText: # How can I disable sessions for most of my Craft site?
  
  (Asked by: username_0 on 2017-01-12)
  
  We're running a craftcms-backed site that uses sessions only for the admin pages.
  
  For a few reasons, we'd like to disable session logic for all other urls:
  
  * the `Set-Cookie` header that craft uses to initiate a session makes responses uncacheable in our fronting cache layers
  * the code path under `Craft\UserSessionService` is unnecessary overhead for most of our logic, and occasionally adds considerable latency
  
  We've been using `HeaderHelper::removeHeader('Set-Cookie');` on a per-controller basis to turn off this behavior, but that only gets us so far - for example, `404` responses seem to try to initiate user sessions as well, before any of our custom logic can be used:
  
  [![This is a screenshot of newrelic transaction trace for a 404 response](https://i.sstatic.net/7azls.png)](https://i.sstatic.net/7azls.png)
  (This is a screenshot of newrelic transaction trace for a 404 response)
  
  How can we get craftcms to stop trying to set these sessions?
  
  I should note that we're looking into getting session storage out of the filesystem and into redis, which should also help - but most of the sessions we're keeping are meaningless, and I'd rather not keep track of them at all.
  
  **Tags:** config, session, cookies
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-12. Score: 3 | Accepted answer
  
  I'm not sure there is going to be an easy way to do this in Craft 2, unfortunately.
  
  In the upcoming Craft 3, we refactored the session logic so that a session will only get started on requests that actually *need* session, which is basically what you're looking for.
  
  > **Comments:**
  > **username_2**: Excellent. As an side, this is going to make full page caching a lot easier from the server side.  
  
  ---
  
  