<p>You're likely running into Craft's <a href="https://craftcms.com/docs/config-settings#userSessionDuration" rel="nofollow noreferrer">userSessionDuration</a> config setting.  It defaults to one hour and will automatically log you out (thereby destroying your session) after reaching that period of inactivity.</p>

CC BY-SA 3.0
2017-09-06T19:21:44.020Z
What's weird is I'm not even logged into Craft. Does a a userSession exist even if you haven't authenticated? 

I tried setting userSessionDuration to PT8H but that didn't resolve the issue (I also am not sure if the T is needed for an hours interval which could've been the case).
Exziled
CC BY-SA 3.0
2017-09-06T21:22:49.060Z
Oh... thought you were referring to an authenticated Craft session.  If it's just PHP session, there are php.ini settings for that: https://stackoverflow.com/questions/9904105/php-sessions-default-timeout
Brad Bell
CC BY-SA 3.0
2017-09-05T18:17:57.257Z
2017-09-05T18:17:57.257Z
Brad Bell
<p>If you're running on Ubuntu, this will be relevant as well: <a href="https://nystudio107.com/blog/the-case-of-the-missing-php-session" rel="nofollow noreferrer">The Case of the Missing PHP Session</a></p>

CC BY-SA 3.0
2017-11-05T16:51:52.237Z
2017-11-05T16:51:52.237Z
andrew.welch
<p>It seems that after x amount of time (somewhere between 30-60 mins?) of inactivity on a page the session is being destroyed/cleared/etc.</p>

<p>I will sit on a page with an active session for an hour and make 0 calls to the PHP. The next time I make a call to my PHP the session is completely gone. I have 0 variables in my session. I'm logging in the beforeAction and the session is just an empty array.</p>

<p>I thought it was my custom code that was clearing the session accidentally but before my code even executes the session is gone which leads me to believe it has something to do with Craft bootstrapping up to receive the PHP request.</p>

<craft-features><session>
Session destroy due to inactivity?
# Session destroy due to inactivity?

(Asked by: username_0 on 2017-09-05)

It seems that after x amount of time (somewhere between 30-60 mins?) of inactivity on a page the session is being destroyed/cleared/etc.

I will sit on a page with an active session for an hour and make 0 calls to the PHP. The next time I make a call to my PHP the session is completely gone. I have 0 variables in my session. I'm logging in the beforeAction and the session is just an empty array.

I thought it was my custom code that was clearing the session accidentally but before my code even executes the session is gone which leads me to believe it has something to do with Craft bootstrapping up to receive the PHP request.

**Tags:** craft-features, session

---

## 2 answers

### Answer by username_1 on 2017-09-05. Score: 1

You're likely running into Craft's [userSessionDuration](https://craftcms.com/docs/config-settings#userSessionDuration) config setting. It defaults to one hour and will automatically log you out (thereby destroying your session) after reaching that period of inactivity.

> **Comments:**
> **username_0**: What's weird is I'm not even logged into Craft. Does a a userSession exist even if you haven't authenticated?   I tried setting userSessionDuration to PT8H but that didn't resolve the issue (I also am not sure if the T is needed for an hours interval which could've been the case).  
> **username_1**: Oh... thought you were referring to an authenticated Craft session.  If it's just PHP session, there are php.ini settings for that: https://stackoverflow.com/questions/9904105/php-sessions-default-timeout  

---

### Answer by username_2 on 2017-11-05. Score: 1

If you're running on Ubuntu, this will be relevant as well: [The Case of the Missing PHP Session](https://nystudio107.com/blog/the-case-of-the-missing-php-session)


---

