We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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

//sleep for 2 secs

 $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

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: https://stackoverflow.com/questions/12401358/why-should-session-write-close-be-used-in-long-polling