1

Update: The usage of the sessions is the problem when calling the polling page because it's already open one time.

I'm doing a long polling on my web app.

For now i'm just doing something like: (the final goal is do a query then sleep, then a query, then sleep,...)

sleep(10);
echo 'ok';

on my server side (just to test it)

The issue : when i try then to load another page it's always taking 10 seconds.

Jerome Ansia
  • 6,854
  • 11
  • 53
  • 99
  • How many threads and processes does Apache have going? There's a decent chance you're using all of Apache's resources and it's having to wait until a request finishes to serve a new one. – Corbin Apr 05 '12 at 20:27
  • 1
    Yep. `sleep()` will tie up the Apache worker. Good way to denial-of-service yourself out of existence. – ceejayoz Apr 05 '12 at 20:28
  • ahah ok... another way to do it without using sleep then, the goal is to query a data base every now and then to check if there is new stuff but between my queries i should us something like sleep if not the server will... explode ;) – Jerome Ansia Apr 05 '12 at 20:29
  • I'm really working on that for... a long time :/ – Jerome Ansia Apr 05 '12 at 20:36
  • run the script as a cron every x minutes – Matt K Apr 05 '12 at 20:41
  • 2
    Are you using sessions? The default file-based handler will lock the session file while a script is using it, preventing any parallel session-using requests from occuring at all. – Marc B Apr 05 '12 at 20:58
  • Marc B looks like you're right, i did another page pull.php to test if it was calling by index.php the problem, it seems to solve it then i did my session_start(); in it and stuck... any work around for this or idea? I'm really stuck big time on this :( – Jerome Ansia Apr 05 '12 at 21:05
  • There's some more useful information on this from a question I asked recently: http://stackoverflow.com/questions/9730857/long-polling-with-php-on-apache – Jeremy Harris Apr 05 '12 at 21:08
  • yes it's definitely the polling page with the session_start that makes everything crash, so one of the solution which will be painful and stupid is to manage to work this polling page without using any session. I see nothing else for now. Thanks again Marc B for this big hint ;) – Jerome Ansia Apr 05 '12 at 21:13
  • 2
    @jeron: use `session_write_close()` to relinquish the session within the sleeping script. The $_SESSION data will still be available for reading. – Marc B Apr 05 '12 at 21:24
  • ok that solved my problem, thanks again you can post it as an answer. Alone i'll have spend days figuring the problem i think (i've already spend 7/9 hours on it)... I'm really glad :) – Jerome Ansia Apr 05 '12 at 21:29

1 Answers1

2

Use session_write_close() to relinquish the session within the sleeping script. The $_SESSION data will still be available for reading. by Marc B

Jerome Ansia
  • 6,854
  • 11
  • 53
  • 99