Thanks to visit codestin.com
Credit goes to github.com

Skip to content

some times session wont save automatically #6481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scourgen opened this issue Dec 26, 2012 · 6 comments
Closed

some times session wont save automatically #6481

scourgen opened this issue Dec 26, 2012 · 6 comments

Comments

@scourgen
Copy link
Contributor

my conf:

services:
    session.memcached:
        class: Memcached
        calls:
          - [ addServer, [ 127.0.0.1, 11211 ]]

    session.handler.memcached:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
        arguments: [ @session.memcached, { prefix: zuo_session, expiretime: 3600 } ]

framework:
    session:
        handler_id: session.handler.memcached

my controller:

    /**
     * @Route("/about",name="aboutMe")
     * @Template()
     */
    public function meAction()
    {
        $v=rand(1,9999);
        ld($v);
        $this->get('session')->set('aaaaaaaaa',$v);
        return new \Symfony\Component\HttpFoundation\RedirectResponse('/advice');
    }

    /**
     * @Route("/advice",name="aboutAdvice")
     * @Template()
     */
    public function adviceAction()
    {
        ld($this->get('session')->get('aaaaaaaaa'));
        return array('title' => 'aaa');
    }

so what I did is:
1.generate a random number on page A
2.dump the number
3.Save the number into session on page A
4.redirect to Page B
5.dump the number which has been saved into session on page A

Normally, I will get 2 same number on page A and page B

but,some times, I will get the different number on Page B which has been save on last turn on Page A.

I guess the problem is because the save function of session hasn't been called automatically?

@bamarni
Copy link
Contributor

bamarni commented Dec 28, 2012

It looks similar than #6417, actually the session is physically writed at the end of the script, but after the response is sent back to the webserver, there is still a kernel.terminate event to be processed, if it takes some time, it means your browser could likely receive the redirect response and then request the next resource before the original script finishes, which means you'll get obsolete session data.

@scourgen
Copy link
Contributor Author

I've tried disable fastcgi_finish_request function and ob_flush ,but the problem stil here,so I think It may not related.

@bamarni
Copy link
Contributor

bamarni commented Dec 29, 2012

It depends on your installation, but if you have apache + mod_php, the first function should be useless and I don't think ob_flush would be enough, you should also try to remove flush in the Response::send() method.

@scourgen
Copy link
Contributor Author

thanks @bamarni ,I will have a try and ping you back when I have result.

@ghost
Copy link

ghost commented Jan 4, 2013

Can you try this: #6417 (comment) just to eliminate one possibility?

@Tobion
Copy link
Contributor

Tobion commented Apr 11, 2014

Closed as duplicate of #6417

@Tobion Tobion closed this as completed Apr 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants