[Core] Allow parallel handling of requests from same session
This adds a session_write_close() call to the end of NDB_Client, after the last reference to $_SESSION has been made. This causes PHP to release the lock it holds on the session file which prevents further incoming requests from being handled. After this point in NDB_Client all of our session related state should be read from the PSR request, not the superglobal.
PHP by default holds a lock on the session until it is closed in case there is a write to the superglobal. However, this prevents other requests from the same session from reading the variable (which is where our login state is stored) until the end of the request, when the lock is released. Closing it explicitly releases the lock and allows us to handle multiple requests from the same user in parallel instead of in series.
I think I found write operations on $_SESSION['State'] that occur after session_write_close
- https://github.com/aces/Loris/blob/c38f1c1ea4bef8112882e0bf48c81a1c13337fc3/php/libraries/NDB_Menu_Filter.class.inc#L324
- https://github.com/aces/Loris/blob/c38f1c1ea4bef8112882e0bf48c81a1c13337fc3/php/libraries/NDB_Menu_Filter.class.inc#L332
Thanks.. that looks like dead code, but I think it might actually be why the MRI Violations tests are failing, since MRI Violations hasn't been converted to React yet. Gonna have to think about if there's an easier way to do this than rewriting the module for this PR..
I think since MRI violations is the last module in https://github.com/aces/Loris/projects/8 I might as well just do it and then delete that code in this PR.
This is cool !
Approving. noticeable difference in request speed. currenlty working on CBIGR biobank
Note: Talked to @cmadjar before skipping the tests and we agreed to rely on manual testing the mri violations module for now, because of the significant performance implications for other modules (biobank, eeg, etc)