send two ajax request at the same time in symfony

我们两清 提交于 2019-11-29 12:58:35

When a request comes in, and it tries to start a session, php will check if the same session is in use at that moment. If it is, the new request has to wait till the other request finishes, or releases the session lock.

Your case is the following:

  • first request arrives, lock session
  • second reauest arrives, tries to lock session, has to wait
  • [ 5 sec sleep ]
  • first request finishes, releases lock
  • second request starts, achieves session lock
  • [ 5 sec sleep ]
  • second request finishes

By default symfony starts the session at the beginning of every request.

In pure PHP you can release the session file's lock with session_write_close(). Symfony has the sfUser class which wraps session functinality, you'll need to call it's shutdown() method.

Be advised that if you modify any session data later in that request, it will not get saved.

For a more detailed explanation, read PHP Session write locking and how to deal with it in symfony.

Possibly symfony does something to ajax requests. What happens if you try:

$.ajax
({
    type: "POST",
    url: 'module/action1',
    async: true
});
$.ajax
({
    type: "POST",
    url: 'module/action2',
    async: true
});

?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!