I want to write an application which monitors a few URLs (like a couple hundred) of all branches of school. By monitoring, we mean that it sends requests to those URLs at regular intervals (Interval for each URL is defined by user), and on the basis of the response to those requests, it makes some changes to the web page. This process goes on forever.
Now there were two ways to implement this:
Approach 1. Load the web page into the browser. First get the urls data from the server. Then group together all urls which have the same value of interval. This results in a few groups of URL's (say 10 groups). Then for each group, at regular intervals whose value is defined by the value of interval field, I send an AJAX request to my own local server, which does all the processing and then returns a response to browser. On the basis of the response I make changes to the DOM.
In this case, the first AJAX request for all groups should be fired at (almost) the same time, and then should be fired at the defined intervals. This goes on IN PARALLEL, forever.
I implemented this by using Javascript's timer functions like setInterval() and setTimeout() etc, which are asynchronous and execute at regular intervals; as well as AJAX which is asynchronous.
Approach 2. The above method seems to be overhead for browser and conceptually speaking, reading data in client-side (browser) from the server and then sending it back to server for analysis and then getting a response of analysis on client-side and then on the basis of the response, making changes in the look of the webpage, JUST DOES NOT FEEL RIGHT.
Rather I should keep the analysis-at-regular-intervals thing at the server, and then insert the results of analysis in database, and then from the browser periodically send requests to my server to read the results of analysis from database, and on the basis of response of this periodic request, make changes in webpage DOM.
For this, I tried to use PHP, but PHP does not support multi-threading and solutions like opensource Asynctask class become overly complicated (unable to enable pcntl extension, no support for pcntl in windows environment); I have considered Java, as it supports multi-threading and creating a separate thread for every group will be simple.
So which approach is correct or better? What programming language should I use - Plain Javascript for the approach 1, or PHP or Java for approach 2.