I am now developing a mobile app using ionic framework and it's using larvel 4 REST API to do CRUD operations with MySql database. Based on the app requirement, the mobile app needs to call backend service everytime in order to complete certain process. I am using Angular Resource to call those APIs and i am calling them every 3 secs using Javascript setinterval function. However, the app is working, I don't really feel that it's a good practice to do because it's a heavy task for both server and client. Could you guys please guide me how I should solve this kind of situation and i really appreciate your help. Especially, which kind of tools I should setup and what are they? Thank you.
Asked
Active
Viewed 946 times
0
-
I think it could help http://stackoverflow.com/questions/29868003/refresh-events-in-angular-calendar-ui-fullcalendar-with-laravel-as-a-backend/29868502#29868502 – Marcus Henrique Apr 26 '15 at 16:41
-
1better not to use `setInterval` in either case. It doesn't account for the time lag for requests. Better to call setTimeout within success and error callbacks – charlietfl Apr 26 '15 at 16:46
1 Answers
0
setInterval
isn't a best practice to receive new data from your API server/DB because the server could get flooded when too many users access your web site. However there is a prettier solution: WebSockets
. With websockets you receive notifications realtime. I am not a PHP developer so I don't know what WebSocket libraries are used for Laravel/PHP development. But on the AngularJS part I can recommend this: https://github.com/gdi2290/angular-websocket
A WebSocket example (non-related): http://jsfiddle.net/EAVvQ/24/
Hope this helped.
Cheers!

Andrei CACIO
- 2,101
- 15
- 28
-
Thanks Andrei, it's really helpful for me and appreciate your answer. Other than Laravel/PHP environment, what are the others? Are you using some of them? I am quite okay to change the environment if it's not super hard. – Hein Apr 27 '15 at 01:02
-
the Laravel/PHP env is just fine. WebSockets is a multi platform/technological library. It doesn't matter what language you use. Try a few PHP WebSockets libraries and see which one fits best. Under the hood WebSockets is just a simple server which sends notifications when they happen and the client (JS) listens for those notifications and performs some actions based on the response. – Andrei CACIO Apr 27 '15 at 08:07