Jump to content

Recommended Posts

I've been toying around with the concept of long polling (I'll explain below), but I'm starting to think that I may not be implementing it very well.

 

Long polling is a method where the client browser opens up a request to the server, but the server intentionally doesn't return a response right away. Instead, it waits until whatever information the client wanted is ready and then sends that information back. Once the client gets the information, it can open another connection to the server to wait for more information. Basically, this is a method to allow the server to push information to the client, rather than require the client to continually poll the server for updates.

 

The PHP sleep function seems to apply on a session basis (yes I have read the docs and it is quite clear on that point 8) ). This poses problems with long polling because if I sleep script execution for 2 seconds, the user can't access other scripts during those 2 seconds.

 

tldr; Is there any way I can call a sleep function and just apply it to a single script execution, not the entire session?

I should have mentioned , based on the logic of what I want to do it will be like this:

 

* Open a connection

* Wait for some flag in the database to be set (sleep)

* Once the flag is set, do some transactions with the database

* Modify some session variables

 

I actually somewhat glazed over that because I will be writing to the session after I am done waiting (ie. I am still using the session). Of course, that is dumb of me because I can always just reopen the session.

 

Thanks for the sanity check :).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.