-
Notifications
You must be signed in to change notification settings - Fork 524
Description
As we implemented VueJS on several parts of the system, we started noticing issues with session (PHP session, that is) access for users, initially only in the social network, but we noticed it some other places as well.
One quick fix has been to use Redis as session handler, but that introduces a dependency on the php-redis extension and, of course, on an available Redis server.
This, in turn, reduces drastically the possibility for people to install Chamilo on cheap hosting solutions from popular web hosting companies, because a Redis server instance is rarely available through cPanel and the likes.
So this is an important issue to fix, in my view.
How to reproduce
- Do not use Redis as session handler as is suggested by the installation guide
- When loading the social network, open the Networking tab of the browser debugger and observe the responses to the different AJAX/XHR calls. Some of them will most likely fail (not all of them)
We attribute this to the slow access to session files when they are stored on disk and the attempt at concurrent access by the many XHR calls trying to access those files, but to be honest we are not 100% sure.
Most of Chamilo will still work without Redis, but we're still in Alpha/Beta, so no high load situation has been had in production just yet.
How to fix
Managing sessions expertly require to know when using a session is done and making sure it is closed (access to the file is closed) as soon as possible. This is done using session_write_close(), essentially, but also ensuring that script loaded through XHR access the session the least possible, and if they do, only access it in read access, not write access.
In particular, it's worth reading the comments in session_write_close(), like
`You can have interesting fun debugging anything with sleep() in it if you have a session still active. For example, a page that makes an ajax request, where the ajax request polls a server-side event (and may not return immediately).
If the ajax function doesn't do session_write_close(), then your outer page will appear to hang, and opening other pages in new tabs will also stall.`