为什么应该在长轮询中使用session_write_close? [英] Why should session_write_close be used in long polling?

查看:94
本文介绍了为什么应该在长轮询中使用session_write_close?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Nolithius .在 PHP在整个会话中休眠一节中,写道,应调用session_write_close函数,以防止整个会话陷入僵局.死锁到底是什么意思?这是否意味着没有此功能,在客户端打开的同一域中的任何其他页面都将无法从其他脚本(如此脚本)接收AJAX数据,直到该脚本执行完毕并返回结果为止?为什么会发生这种情况?以及session_write_close在这里如何提供帮助?收到请求的数据后,下次他下次从该域请求页面时,是否会使用它从客户端删除所有个性化设置?

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?

推荐答案

这是我的理解:

使用基于文件的会话时,每个请求都会从字面上锁定文件,直到请求结束.

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.

使用session_write_close()将清除(但不会丢失任何会话数据)并更早地释放文件上的锁,以允许其他请求继续.

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.

这篇关于为什么应该在长轮询中使用session_write_close?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆