Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

sleep() stops all my Phalcon scripts

I'm using the Long Polling technique for my notification system (a facebook like notification for my single page app with ajax).

I used the sleep(2000) function for every database checking for new notifications:

Controller : notificationsController

Action: indexAction

<?php
//.......
while(count($notifications)==0){
//sleep for 2 secs
 sleep(2000);

 $notifications = Notifications::find('for_user_id = '.$this->userSession->id);
}
//some notifications found!
return $notifications

It works well, but the problem is that all my scripts that uses the Phalcon framework are stopped by this sleep(2000),* I mean not only my current Phalcon app, all the phalcon apps that are located in different folders and wait for the boucle to end.*

I think this is a problem from Phalcon ?

Using: WampServer Version 2.2 64bits on Windows 8.1 64bits



14.2k
Accepted
answer
edited Apr '14

Here I found a solution for this problem,

you have to use the session_write_close(); for each sleep().

and it's not from Phalcon, sorry for that :)

explanation here: http://stackoverflow.com/questions/12401358/why-should-session-write-close-be-used-in-long-polling