SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Session use interferes with XHR Abort

    Hello All,

    Perhaps one of the deep geeks out there can help me understand why my attempts to abort XHR requests don't work when cache-control headers (or possibly cookies) are involved?

    I have some generic javascript that responds to menu clicks by loading associated UI panels (using Prototype's Ajax.Update). The code works fine. If a user selects a new menu option before the previous request has finished retrieving the UI panels, the earlier requests are aborted and the new requests take over. This too works fine, unless I use sessions in the underlying PHP. When I use sessions the abort commands don't abort, each XHR response is still received (the browser waits for all to finish, even the aborted requests).

    That's the only difference... use sessions, it fails. Don't use sessions and it works fine. There is nothing special about the session code (in fact it does nothing at the moment but establish the session tracking cookie). The XHR response include cache control headers (no-cache) in the failure scenario.

    I've tried this in Firefox and Safari and they both respond the same. Perhaps I'm failing to understand something about the request response cycle. I thought the abort only affected the browser (stop watching for the server response).

    Any clues or resources? Thanks.

    chris

  2. #2
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bad form, I know but I was finally able to resolve my issue after a great deal of digging. This is ultimately a PHP issue. Simply, PHP manages session concurrency issues through locking. As long as the session is "open" (session_start()) PHP will refuse to abort the response. When the script finally ends, PHP finally acknowledges the abort.

    My solution was to wrap each use of session values in session_start() and session_write_close(). Fortunately my use of sessions is limited.

    chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •