Long Polling Yii2

Hi everyone !!

I am trying to achieve Real Time Notification in Yii2 from my external database(Moodle). I try to look for options and come across Long Polling and Server Side Events. How is this possible with Yii2 ?? Or any other alternative ??

Yes, it’s possible. In order to do long polling you have to make sure your server isn’t terminating connections fast and that it could keep tons of such connections open at the same time. As for PHP side, you have to do while (true) type of cycle which writes data as it becomes available and flushes output.

Overall I think long polling is inefficient and prefer websockets to it: https://github.com/nizsheanez/yii2-websocket-application

server side events are not possible with Yii2 - at least not if you are using it as a backend server. i just spent several hours attempting to make it work with no success. this is because SSE requires a continuous stream of output and Yii controllers do not allow you to echo data. you can only return data. this ends the connection and defeats the whole purpose of server side events.

Well, you can run Yii in an endless loop. I saw apps like that which used Yii.