Welcome Guest, Not a member yet? Register   Sign In
Session reverting back to previous state after slow ajax call finishes
#21

[eluser]brainer[/eluser]
Okay guys, thanks a lot for the help. I think I know where I stand now.
#22

[eluser]pickupman[/eluser]
This is an open bug. [url="https://bitbucket.org/ellislab/codeigniter-reactor/issue/262/rapid-requests-during-session-updates"]Issue 262[/url]. I have posted a link to WanWizards solution to explicitly write the session when the ajax request has complted.
#23

[eluser]brainer[/eluser]
Hi pickupman, i'm experiencing a different issue to the one described in that bug. The problem I have has no correlation with session update time.

Regardless, I tried WanWizards session library anyway but the problem persists.
#24

[eluser]brainer[/eluser]
Solved it.... finally!

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Session extends CI_Session
{
  
    /**
     * Add or change data in the "userdata" array
     *
     * @access    public
     * @param    mixed
     * @param    string
     * @param    bool    if set to true we will grab the session data from database again
     * @return    void
     */
    function set_userdata($newdata = array(), $newval = '', $get_again = false)
    {
        if($get_again) $this->sess_read(); // just in case the session has been updated elsewhere after the Session library was loaded here
        
        if (is_string($newdata))
        {
            $newdata = array($newdata => $newval);
        }

        if (count($newdata) > 0)
        {
            foreach ($newdata as $key => $val)
            {
                $this->userdata[$key] = $val;
            }
        }

        $this->sess_write();
    }

}

/* End of file MY_Session.php */
/* Location: ./application/libraries/MY_Session.php */

So, I added a third param $get_again, which if set to true will make sure that the session library has the most up to date session info.

Hope this is of some use to someone...
#25

[eluser]brainer[/eluser]
Actually, instead of extending the library I could just do something like this:

Code:
function some_long_call()
    {
        sleep(20);  
    
        $this->session->sess_read();
        $this->session->set_userdata(array('foo' => 'bar'));
    }

This is a cleaner solution for my setup.

EDIT: Actually, this causes errors.
#26

[eluser]InsiteFX[/eluser]
Code:
function some_long_call()
{
    if ( ! $this->input->is_ajax_request())
    {
        $this->session->sess_read();
        $this->session->set_userdata(array('foo' => 'bar'));
    }  
}

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB