Answers.Body: <p>My own answer... for anyone interested, the Memcached extension in my composer.json file wasn't being picked up by Heroku on deploy. So I updated my composer.json file like this:</p>
  
  <pre><code>{
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*",
      "ext-memcached": "*"
    }
  }
  </code></pre>
  
  <p>Then ran composer update to update the composer.lock file.</p>
  
  <p>When deploying to Heroku, the composer.lock file is very similar to the Gemfile.lock in Rails - telling Heroku exactly what to install with the deployment. Now the Memcached extension is being installed by Heroku and my session problem has been solved.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-15T06:35:42.573Z
Answers.LastActivityDate: 2015-12-15T06:35:42.573Z
Answers.UserDisplayName: chrisyour
Answers.Body: <p>It sounds like PHP/Apache can't write to where it is <a href="https://secure.php.net/manual/en/function.session-save-path.php" rel="nofollow">configured</a> to save PHP session files.</p>
  
  <p>I'd first double check that path exists and is writable by PHP.</p>
  
  <p>Not real sure what <code>composer.json</code> has to do with this, though.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-13T22:39:34.637Z
Answers.Text: They must be writable, since the save path is set to the Memcached server. I can also log in for a short duration.
Answers.UserDisplayName: chrisyour
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-13T23:20:58.497Z
Answers.Text: Are you on a load-balanced web server setup?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-14T05:15:28.653Z
Answers.Text: Heroku is load balanced, using request distribution and the router to send requests to Heroku dyno processors. (https://devcenter.heroku.com/articles/http-routing#routing)
  
  I think the problem may have to do with going from the HTTPS admin URL to a regular HTTP request for the public facing website. When I force HTTPS through .htaccess, everything seems ok. When Craft bounces me back and forth between HTTPS and HTTP that's when the session seems to get removed. Then the log in modal appears.
Answers.UserDisplayName: chrisyour
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-14T05:55:39.077Z
Answers.Text: Hrm... that workflow works in a non-Heroku environment, so maybe it's a combination of that + being load balanced? Curious... does it help if you set https://craftcms.com/docs/config-settings#appId ?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-14T05:56:52.850Z
Answers.Text: lol - just saw your edit.  Nice find! Would you mind adding that as an official answer instead of modifying the original question?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-15T06:38:18.623Z
Answers.Text: Hi Brad, thanks for checking back in on my question. I appreciate it! I've added my own answer from my edit in the answers below. I get to accept it as the preferred answer in 14 hours or so. Thanks for all the links and overall helpfulness.
Answers.UserDisplayName: chrisyour
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-15T17:52:44.387Z
Answers.Text: No worries... you got my vote! :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-13T22:21:21.423Z
Answers.LastActivityDate: 2015-12-13T22:21:21.423Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have Craft installed on Heroku using Memcached for sessions. Craft is kicking me out of the admin area every minute or two. It's deriving me crazy. I've also set the user session duration in general.php:</p>
  
  <pre><code>'userSessionDuration' =&gt; 'P2W'
  </code></pre>
  
  <p>Still kicking me out.</p>
  
  <p>If I set it to dev mode, I get this error: </p>
  
  <pre><code>Undefined variable: _SESSION
  </code></pre>
  
  <p>I know that the session does work, because I can login. I can also check the currentUser variable and see people signed in. The thing is, it isn't lasting long and makes the admin area nearly unusable.</p>
  
  <p>My composer file is really simple. Nothing complicated.</p>
  
  <pre><code>{
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*"
    },
    "require-production": {
      "ext-memcached": "*"
    }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Also, here are my Memcached settings in the /public/.user.ini file (as recommended by Heroku):</p>
  
  <pre><code>session.save_handler=memcached
  memcached.sess_binary=1
  session.save_path="PERSISTENT=myapp_session ${MEMCACHIER_SERVERS}"
  memcached.sess_sasl_username=${MEMCACHIER_USERNAME}
  memcached.sess_sasl_password=${MEMCACHIER_PASSWORD}
  </code></pre>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>For anyone interested, the Memcached extension in my composer.json file wasn't being picked up by Heroku on deploy. So I updated my composer.json file like this:</p>
  
  <pre><code>{
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*",
      "ext-memcached": "*"
    }
  }
  </code></pre>
  
  <p>Then ran <code>composer update</code> to update the composer.lock file.</p>
  
  <p>When deploying to Heroku, the composer.lock file is very similar to the Gemfile.lock in Rails - telling Heroku exactly what to install with the deployment. Now the Memcached extension is being installed by Heroku and my session problem has been solved.</p>
  
Tags: <admin><session>
Title: Logging in Every Minute - Craft Admin Sessions (on Heroku)
ThreadText: # Logging in Every Minute - Craft Admin Sessions (on Heroku)
  
  (Asked by: username_0 on 2015-12-13)
  
  I have Craft installed on Heroku using Memcached for sessions. Craft is kicking me out of the admin area every minute or two. It's deriving me crazy. I've also set the user session duration in general.php:
  
  ```
  'userSessionDuration' => 'P2W'
  
  ```
  
  Still kicking me out.
  
  If I set it to dev mode, I get this error:
  
  ```
  Undefined variable: _SESSION
  
  ```
  
  I know that the session does work, because I can login. I can also check the currentUser variable and see people signed in. The thing is, it isn't lasting long and makes the admin area nearly unusable.
  
  My composer file is really simple. Nothing complicated.
  
  ```
  {
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*"
    },
    "require-production": {
      "ext-memcached": "*"
    }
  }
  
  ```
  
  **EDIT:**
  
  Also, here are my Memcached settings in the /public/.user.ini file (as recommended by Heroku):
  
  ```
  session.save_handler=memcached
  memcached.sess_binary=1
  session.save_path="PERSISTENT=myapp_session ${MEMCACHIER_SERVERS}"
  memcached.sess_sasl_username=${MEMCACHIER_USERNAME}
  memcached.sess_sasl_password=${MEMCACHIER_PASSWORD}
  
  ```
  
  **SOLUTION:**
  
  For anyone interested, the Memcached extension in my composer.json file wasn't being picked up by Heroku on deploy. So I updated my composer.json file like this:
  
  ```
  {
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*",
      "ext-memcached": "*"
    }
  }
  
  ```
  
  Then ran `composer update` to update the composer.lock file.
  
  When deploying to Heroku, the composer.lock file is very similar to the Gemfile.lock in Rails - telling Heroku exactly what to install with the deployment. Now the Memcached extension is being installed by Heroku and my session problem has been solved.
  
  **Tags:** admin, session
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2015-12-15. Score: 1 | Accepted answer
  
  My own answer... for anyone interested, the Memcached extension in my composer.json file wasn't being picked up by Heroku on deploy. So I updated my composer.json file like this:
  
  ```
  {
    "require": {
      "ext-mbstring": "*",
      "ext-imagick": "*",
      "ext-memcached": "*"
    }
  }
  
  ```
  
  Then ran composer update to update the composer.lock file.
  
  When deploying to Heroku, the composer.lock file is very similar to the Gemfile.lock in Rails - telling Heroku exactly what to install with the deployment. Now the Memcached extension is being installed by Heroku and my session problem has been solved.
  
  
  ---
  
  ### Answer by username_1 on 2015-12-13. Score: 0
  
  It sounds like PHP/Apache can't write to where it is [configured](https://secure.php.net/manual/en/function.session-save-path.php) to save PHP session files.
  
  I'd first double check that path exists and is writable by PHP.
  
  Not real sure what `composer.json` has to do with this, though.
  
  > **Comments:**
  > **username_0**: They must be writable, since the save path is set to the Memcached server. I can also log in for a short duration.  
  > **username_1**: Are you on a load-balanced web server setup?  
  > **username_0**: Heroku is load balanced, using request distribution and the router to send requests to Heroku dyno processors. (https://devcenter.heroku.com/articles/http-routing#routing)  I think the problem may have to do with going from the HTTPS admin URL to a regular HTTP request for the public facing website. When I force HTTPS through .htaccess, everything seems ok. When Craft bounces me back and forth between HTTPS and HTTP that's when the session seems to get removed. Then the log in modal appears.  
  > **username_1**: Hrm... that workflow works in a non-Heroku environment, so maybe it's a combination of that + being load balanced? Curious... does it help if you set https://craftcms.com/docs/config-settings#appId ?  
  > **username_1**: lol - just saw your edit.  Nice find! Would you mind adding that as an official answer instead of modifying the original question?  
  > **username_0**: Hi username_1, thanks for checking back in on my question. I appreciate it! I've added my own answer from my edit in the answers below. I get to accept it as the preferred answer in 14 hours or so. Thanks for all the links and overall helpfulness.  
  > **username_1**: No worries... you got my vote! :)  
  
  ---
  
  