Why is session_write_close used for long polls?

I read an article on a lengthy poll on Nolithius . In the PHP section, the whole session falls asleep , it is written that the session_write_close function must be called so that the entire session does not go to a dead end. What exactly is meant by a dead end here? Does this mean that without this function, any other page from the same domain open on the client side will not be able to receive AJAX data from other scripts (for example, this one) until it finishes execution and returns the result? Why is this supposed to happen? And how to help session_write_close here? Will he delete all personalization on the client side the next time a page is requested from this domain after receiving data from this request?

+8
php session long-polling
source share
1 answer

This is my understanding:

When using file-based sessions, each request literally locks the file until the end of the request.

The value is that the next request (which also uses session data) must wait for the lock to be released.

This is used to prevent corrupted session data.

Using session_write_close() will clear (but not lose session data) and release the lock earlier in the file so that other requests continue.

This is good practice, especially if you have scripts that often sleep.

+15
source share

All Articles