Yoga Arnindita Yoga Arnindita - 3 days ago 6
PHP Question

Codeigniter session data lost after redirect (after using memcached as session storage)

I had a server with many PHP applications using CodeIgniter as the framework. Everything's running perfectly.

However, after using Memcached as the session storage (I used default file to store sessions before), one of my applications reacted strangely. While others are running well, few of my applications' session missing after redirecting to homepage.

For debugging, I use statement like this

class Home extends CI_Controller {

public function __construct()
{
parent::__construct();
// Your own constructor code

var_dump($_SESSION); die;

$this->mysession->check_no_session();
$this->mysession->check_session_expires();
}

public function index()
{
$this->libs->check_main_template('welcome_message','');
}
}


The dump shows me nothing stored in the session:
array(0) { }


But in my other applications in the same server, when I do debugging, the session data displayed perfectly.

I built these applications using a template, meaning that all configs mostly are the same, so what config/file do I have to see to identify/compare between the OK and error application to spot the config that might cause this anomaly?

Any idea? Thanks in advance for the help.

Answer

Ok i think I have found the root cause.

Apparently one of my colleagues set a directive on index.php in the application that exceeds memcache's limitation, like this:

define('SESSION_TIME_OUT', x);
ini_set('session.gc_maxlifetime', SESSION_TIME_OUT);
ini_set('session.cache_expire', SESSION_TIME_OUT);
session_start();

Replace x with an appropriate number (memcache only accepts numbers under 2,592,000 or 30 days), then the issue no longer exists.

Comments