session_write_close symfony 2 and 3

Viewed 1581

php/symfony experts!

This question especially for you.

try this code example

/**
 * @Route("/your-route", name="your-route")
 */
public function indexAction()
{

    $this->get('session')->save();

    sleep(10);

    return $this->render('template.html.twig');
}

requests are performing in parallel in different browsers as expected, but why sequentially in the same browser?

2 Answers

Your code should perform in parallel, if the web server supports multiple parallel requests.

Normally, when a previous request is still running with session storage opened, and a subsequent request calls session_open() trying to access that same session, executions stops until the previous request ends or its session is closed with session_write_close(). The Session::save() method, which you are calling, does exactly this, so your code is correct.

I was facing your same issue, and then I realized that I was using the php built-in web server, which can process one single request at time.

Related