1

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.

2 Answers 2

1

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.

0

It sounds like PHP/Apache can't write to where it is configured 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.

7
  • They must be writable, since the save path is set to the Memcached server. I can also log in for a short duration.
    – chrisyour
    Commented Dec 13, 2015 at 22:39
  • Are you on a load-balanced web server setup?
    – Brad Bell
    Commented Dec 13, 2015 at 23:20
  • Heroku is load balanced, using request distribution and the router to send requests to Heroku dyno processors. (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.
    – chrisyour
    Commented Dec 14, 2015 at 5:15
  • 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 craftcms.com/docs/config-settings#appId ?
    – Brad Bell
    Commented Dec 14, 2015 at 5:55
  • lol - just saw your edit. Nice find! Would you mind adding that as an official answer instead of modifying the original question?
    – Brad Bell
    Commented Dec 14, 2015 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.