Menu

session_start locking/blocking

Developers
Kevin Yeh
2012-05-01
2013-04-06
  • Kevin Yeh

    Kevin Yeh - 2012-05-01

    Only one AJAX call (or page load) can execute at a time when the script calls session_start
    http://php.net/manual/en/function.session-start.php

    PHP locks the session file until it is closed. If you have 2 scripts using the same session (i.e. from the same user) then the 2nd script will not finish its call to session_start() until the first script finishes execution.

    If you have scripts that run for more than a second and users may be making more than 1 request at a time then it is worth calling session_write_close() as soon as you've finished writing session data.

    So part of the reason the demographics page takes a long time to complete is that each AJAX get called synchronously.

    I've done some initial coding and you can see the difference.  (My vitals load in less than half a second where as before it was waiting until after the 2 seconds the clinical rules needed to complete).

    https://github.com/yehster/openemr/tree/ajax-sessions-experiment

    I'm not sure of other unintended consequences this might have though.  I've scanned the files where I added session_write_close() to make sure that no attempts to change session variables are made after that point, but I could certainly have missed it.

    Like I said, this issue applied to page loads in addition to AJAX, so when you load a new patient with the frames model, the encounters.php in the bottom frame has to wait for the demographics page to finish in the top frame.

    Here is another useful explaination.
    http://konrness.com/php5/how-to-prevent-blocking-php-requests/

     
  • Brady Miller

    Brady Miller - 2012-05-02

    Hi,
    This is very cool. As discussed on github, will be important to document this on the wiki for developers.
    -brady
    OpenEMR Project

     
  • Brady Miller

    Brady Miller - 2012-05-23

    Hi,
    Just bumping this thread since would be nice to get this incorporated into the 4.1.1 release. (Guessing will help to run the large multi-patient CDR based reports (after ajaxified) concurrently with normal use also)
    -brady
    OpenEMR

     
  • Kevin Yeh

    Kevin Yeh - 2012-05-24

    (Guessing will help to run the large multi-patient CDR based reports (after ajaxified) concurrently with normal use also)

    No, it won't.  The mechanism to processes patient reminders would need to wait for each individual batch to complete anyway since each batch uses session variables to keep track of the overall state.
    The primary place where it helps is when multiple things are loading in separate frames, or multiple operations (like on the demographics page) are taking place simultaneously. 

     
  • Brady Miller

    Brady Miller - 2012-05-24

    Hi,
    I see what you mean. Still would be nice to get this included in 4.1.1 release to optimize the patient summary screen.
    -brady
    OpenEMR Project

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.