📜 ⬆️ ⬇️

Sessions in PHP - an underwater pebble with asynchronous requests

A little background.

I have a hobby project tracker.ru
The algorithm is as follows: the user enters a search query, this query “on the fly” searches for torrents on third-party trackers (rutor, root-tracker, tfile, etc.).
For parallel search, there are several AJAX requests that must be processed asynchronously.
However, requests were executed synchronously. If some tracker didn’t give an answer for a long time, then the rest of the requests hung up and waited for a response from the hung tracker. The total time for the execution of requests was equal to the sum of all requests. Although, according to my plans, the total time should be equal to the longest request.
Long puzzled why so. Sinned on HTTP pipelining . But the reason turned out to be much more banal. It's all about the sessions. The fact is that sessions in php are consistent and php will not allow another process to turn to an already occupied session.

Poke and admire the result can be here . Look at the total time with and without sessions.

What is bad:

If the site slows down, then when you open several tabs of this site, the tabs will be loaded one by one.
If your content is loaded with multiple ajax requests, then they will be executed in turn too.

How to treat?

Changing session handlers will not help. corrected in the comments that it is not.
As an option - (this was already written on Habré) in the quick code section to use the session, and then execute session_write_close ();

')

Source: https://habr.com/ru/post/232305/


All Articles