Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Session, Zend_Session_SaveHandler_DbTable and Asynchronous Requests

I am using Zend Session combined with Zend_Auth and Session Namespaces in the following fashion:

application.ini

    resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
    resources.session.saveHandler.options.name = "session"
    resources.session.saveHandler.options.primary = "id"
    resources.session.saveHandler.options.modifiedColumn = "modified"
    resources.session.saveHandler.options.dataColumn = "data"
    resources.session.saveHandler.options.lifetimeColumn = "lifetime"

Bootstrap

     /**
     * Start session 
     */
    public function _initCoreSession() {
        $this->bootstrap('db');
        $this->bootstrap('session');
        Zend_Session::start();
    }

While the Zend_Auth seems to work fine, the other session namespaces seem to behave oddly.

I use several Asynchronous requests (using jQuery).

-Init (intializes an array into the session)

    $ns = new Zend_Session_Namespace('scanner');
    $ns->unsetAll();
    $ns->pages = array();

-Loop (puts stuff into array, this part is called 1 to n times)

    //Fetch the Session Namespace
    $ns = new Zend_Session_Namespace('scanner');
    //Set scanned page to true
    $ns->pages[$this->getRequest()->getParam('nextUrl')] = true;

-Finalize (processes the array)

    //Fetch the Session Namespace
    $ns = new Zend_Session_Namespace('scanner');
    //Do stuff with $ns->pages

However somewhere in the calls to loop the pages variable seems to be reset (and thus null).

This works in the default session behaviour, but it starts to fail when i set Zend_Session_SaveHandler_DbTable.

*EDIT*

As a response to the first answer (cause it required a code block)

I am using $.post to make requests to my application. Where it sends a request with data (an URL) to the application, and it receives a status update and an url to request next. And this loops around until it receives no next url.

jQuery code used

    function scanUrl(url)
    {
        $.post("http://www.example.com/scan/scanurl", { nextUrl: url },
       function(data) 
       {
         updateView(data);

         if(data.nextUrl != null)
             scanUrl(data.nextUrl);
         else
             finalize();
       });
    }
like image 813
Dennis Schepers Avatar asked Jul 13 '26 06:07

Dennis Schepers


1 Answers

Did you pass the session id with your asymc request? if i did not misunderstood and you are calling stuff like this:

$.ajax({ 'url' : 'http://something', ... })

you need to add a 'data' section where you have:

sessionIdVariable=your-current-session-id

like image 150
eemerge Avatar answered Jul 15 '26 19:07

eemerge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!