function sess_update() {
        // We only update the session every five minutes by default
        if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) {
            log_message('info','not enough time before update');
            return;
        }
        log_message('info','defo need to update session');
        
        // Save the old session id so we know which record to
        // update in the database if we need it
        $old_sessid = $this->userdata['session_id'];
        $new_sessid = '';
        while (strlen($new_sessid) < 32) {
            $new_sessid .= mt_rand(0, mt_getrandmax());
        }
        
        // To make the session ID even more secure we'll combine it with the user's IP
        $new_sessid .= $this->CI->input->ip_address();

        // Turn it into a hash
        $new_sessid = md5(uniqid($new_sessid, TRUE));
        log_message('info','session id generated');
        // Update the session data in the session data array
        $this->userdata['session_id'] = $new_sessid;
        $this->userdata['last_activity'] = $this->now;

        // _set_cookie() will handle this for us if we aren't using database sessions
        // by pushing all userdata to the cookie.
        $cookie_data = NULL;

        $cookie_data = array();
        foreach (array('session_id', 'ip_address', 'user_agent', 'last_activity') as $val) {
            $cookie_data[$val] = $this->userdata[$val];
        }
        
        switch ($this->session_storage) {
            case 'database':
                // Update the session ID and last_activity field in the DB if needed
                // set cookie explicitly to only have our session data
                $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));
                break;
            case 'memcached':                
                // Add item with new session_id and data to memcached
                // then delete old memcache item
                $this->memcache->add('user_session_data' . $new_sessid, $this->userdata, false, $this->sess_expiration);
                log_message('info', 'new session added');
                $this->memcache->delete('user_session_data' . $old_sessid, 0);
                log_message('info', 'old session deleted');                
                break;
        }
        // Write the cookie
        $this->_set_cookie($cookie_data);
    }

Ok, so I posted yesterday a link to github with an extension to the CI Session library, but I've been having issues since then with it.

It all works aside from the sess_update() method and I've been struggling with this for a few hours now so I thought I'd post here and see if I can get some help.

The full class can be found here: github.com/pierskarsenbarg/codeigniter-session-memcached/blob/master/…

Basically, it all works fine until it tries to run the above method. I think it has something to do with the part where it adds a new item to memcache and then removes the old one.

Can anyone see where I'm going wrong?

(Oh, and please ignore the log messages. I've been trying to see where it's going wrong and I'm completely stuck)