0

I have a PHP app on Heroku. Users can sign up and sign in; so the sessions do work.

Whenever I make an update ("git pus heroku master") it kills the sessions of the users. Users have to then log back in to the site.

Is there a way to ensure this doesn't happen with every update?

This solution was of similar topic but didn't help.

Community
  • 1
  • 1
user3163139
  • 27
  • 1
  • 5
  • Does your application use the built-in PHP sessions i.e. with `session_start()`? – TheGentleman Jan 23 '17 at 21:45
  • Yes,all files start with: session_start(); ob_start(); and end with: ob_end_flush(); – user3163139 Jan 23 '17 at 21:46
  • What is happening is that php is restarting and as such all outstanding sessions are invalidated. You need to implement session handling as described in in [PHP Session Handling on Heroku](https://devcenter.heroku.com/articles/php-sessions) – TheGentleman Jan 23 '17 at 21:50
  • That got me on the right track, thanks! Now I'm running into the problem of "The requested PHP extension ext-memcached * is missing from your system. Install or enable PHP's memcached extension." -- I'm on a Windows machine using MAMP. Haven't figured out how to enable it yet... – user3163139 Jan 24 '17 at 00:25
  • This might get you on the right track...[How To Install Memcache on MAMP](https://gist.github.com/jakebellacera/3997527) – TheGentleman Jan 24 '17 at 21:20
  • Worth a note that it's ok to use session_start() and a session variable for temporary use, such a a web form with captcha, for example. – Robot70 Mar 05 '18 at 20:53

1 Answers1

0

Heroku platform does not support persistent PHP sessions. You need to use Memcachier addon

https://devcenter.heroku.com/articles/memcachier

For PHP:

  // Create memcache client
  $mSession = new MemcacheSASL();
  $servers = explode(",", getenv("MEMCACHIER_SERVERS"));
  foreach ($servers as $s) {
      $parts = explode(":", $s);
      $mSession->addServer($parts[0], $parts[1]);
  }

  // Setup memcache authentication
  $mSession->setSaslAuthData( getenv("MEMCACHIER_USERNAME")
                            , getenv("MEMCACHIER_PASSWORD") );
$mSession->add($key, $val, $expires);
$stored = $mSession->get($key);
$mSession->replace($key, array('_data' => $data), $expires);
$mSession->delete($key);
Scott Logsdon
  • 71
  • 1
  • 4