aarnott Posted May 26, 2010 Share Posted May 26, 2010 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 ). 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? Quote Link to comment https://forums.phpfreaks.com/topic/202976-is-there-any-way-to-sleep-for-just-a-single-script/ Share on other sites More sharing options...
Adam Posted May 26, 2010 Share Posted May 26, 2010 The second comment on the manual for sleep suggests using session_write_close - don't know if you've seen that? Quote Link to comment https://forums.phpfreaks.com/topic/202976-is-there-any-way-to-sleep-for-just-a-single-script/#findComment-1063644 Share on other sites More sharing options...
aarnott Posted May 26, 2010 Author Share Posted May 26, 2010 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 . Quote Link to comment https://forums.phpfreaks.com/topic/202976-is-there-any-way-to-sleep-for-just-a-single-script/#findComment-1063646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.