Why should session_write_close be used in long polling?

柔情痞子 提交于 2019-12-04 09:32:39

问题


I was reading an article about long polling at Nolithius. Under the section PHP sleeps across the entire session, it is written that the session_write_close function should be called in order to prevent the entire session coming to a deadlock. What exactly is meant by deadlock here? Does it mean that without this function, any other page from the same domain opened in the client side won't be able to receive AJAX data from other scripts (like this one) until this one has finished executing and returned the result? Why should this happen? And how can session_write_close help here? Won't using it remove all personalization from the client side the next time he requests a page from this domain after he has received data from this request?


回答1:


This is my understanding:

When file based sessions are used each request literally locks the file until the end of the request.

Meaning that the next request (that also uses the session data) has to wait for the lock to be released.

This is used to avoid session data corruption.

Using session_write_close() will clean up (but not lose any session data) and release the lock earlier on the file allowing other requests to continue.

This is good practice especially if you have scripts that sleep a lot, probably.



来源:https://stackoverflow.com/questions/12401358/why-should-session-write-close-be-used-in-long-polling

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