Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:30:35+00:00 2026-06-09T20:30:35+00:00

I am buidling some webapp and have implemented long-polling (and a command queue in

  • 0

I am buidling some webapp and have implemented long-polling (and a command queue in my db) so my server can send commands to my cleint asynchronously, etc. The commands are encoded into json and sent over ajax calls for the client to server, and via long-polling for the server to client way.

Everything was working just fine, until I included my “Authentication module” in the ajax.php file. This module wraps the session stuff and calls session_start().

The problem is that, my long polling routine can wait up to 21 seconds before comming back to the client. During this time, the server won’t run anything from the same session. It’s instead executed right after the long polling ajax call returned.

I understand there’s probably a restriction of only 1 thread per session at a time, and that the requests are queued up.

Now here’s the question : What is the best way to address this? Is there a setting to allow several threads per sessions (3 would be fine, in my case). Or should I just send tell the client what is his SessionID (i have some sessions table in my db, to track which user is connected to which session(s)). The client could then send it along with any ajax calls so authentication module could be bypassed.

On the later option, iam afraid it open’s up a bunch of security problems because of eventual session spoofing. I would need to send a “random string” to each session, to make sure you can’t spoof too easily, but even then, it’s not perfect…

Thanks for your awnsers 🙂

Nicolas Gauthier

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:30:37+00:00Added an answer on June 9, 2026 at 8:30 pm

    It’s a well known issue/fact that PHP locks session files for the duration of their usage in order to prevent race conditions.

    If you take a look at the PHP source code, (ext/session/mod_files.c) you can see that the ps_files_open function locks the session file, and ps_files_close unlocks it.

    If you call session_start() right at the beginning of your long-running script, and do not explicitly close the session file, it will be locked until the script terminates, where PHP will release all file locks during script shutdown.

    While you are not using the session, you should call session_write_close to flush the session data to disk, and release the lock so that your other “threads” can read the data.

    I’m sure you can imagine what would happen if the file was not locked.

    T1: Open Session
    T2: Open Session
    ...
    T2: Write Data
    T1: Write Data
    

    The data written by thread 2 will be completely overwritten by thread 1, and at the same time, any data that thread 1 wanted to write out, was not available to thread 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in building a small offline webapp and I'm looking for some advice.
I am fairly new to Flotr2 and I have just been building some simple
I have a webapp that I'm building, and have just started with SQLite. I
I am building a small webapp for my website and have included tinyMCE as
We're going to be building some J2ME apps and Java/Rails webapps which will have
I'm building a webapp where I have a settings panel. I have a code
I've done some searching but haven't quite seen the info I'm looking. I have
i am building a webapp that will have notes fields all over the place,
I am building a webapp that will display PDFs. The PDFs have fillable forms.
I have a PL/SQL procedure with multiple parameters. When a webapp calls the procedure,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.