0

Situation:

I got the page which shows all our servers (we name them resources). The list is obtained from MS SQL database. To show them I fetch them from array and echo. After echo - I send request to every resource to obtain its status (200, 404, 502 etc).

Problem:

When there was 10-20 resources the page loads few seconds, but now there are almost 100 resources (and will be more) therefor the page loads ~1 minute. And now my manager says we need to check status every 1 minute.

So, my question is - how can I achieve this? And generally - can I? :)

I don't need code or working solution, I need some guidance, how I can achieve this? What to search? What to read about? Maybe there is a solution with some library and even some framework that can do this better and simpler?

I have read some articles and questions on SO: http://www.w3schools.com/php/php_ajax_intro.asp Sending data from server to client? fetch data from text file and update web page every minute

And I think I need to learn about AJAX and use it. But any guidance I found was: Live Search, select something from input dynamically, suggestions when typing in field etc.

As I see it there must be a page like I have now servers.php, when I load it it fetches and shows all servers. Then it call check_status.php for every resource and updates data dynamically, then every 1 minute page reloads. But I don't understand how to send that much (~100) request to all servers in one time.

EDIT

We came to this: We will run Linux VM and run cron jobs to stay updated on our resources status. The script that check statuses with Ajax was simple to write as I haven't expected. For storing logs we will use MySQL database and will write simple pages to work with logs. Thank you all for participating in answers and comments!

Community
  • 1
  • 1
gofr1
  • 15,741
  • 11
  • 42
  • 52
  • Certainly you can do that by means of asynchronous calls (so performing all requests _at the same time, in parallel_). However one hint: there are existing and well proven solutions for this, that is called "system monitoring". Popular choices are `zabbix` or `nagios`. Take a look at them and save yourself a lot of hassle... – arkascha May 23 '16 at 05:32
  • you could do it by spawning separate asynchronous requests, but in any case resources are never infinite and that is true for networks too. There are always limits. – ArtisticPhoenix May 23 '16 at 05:33
  • Write function to send request to server (it includes ajax call) and use javascript polling for every minutes to this function. see... http://stackoverflow.com/questions/4930439/call-jquery-ajax-request-each-x-minutes – Nitin Dhomse May 23 '16 at 05:36
  • @arkascha thanks, for your advice, I heard about zabbix, but as you can see never used it :) I will take a look. – gofr1 May 23 '16 at 06:33
  • @ArtisiticPhoenix thanks, resources on that task truly are limited... That's why I'm looking forward to use some tools made specially for this monitoring. – gofr1 May 23 '16 at 06:35
  • @NitinDhomse thank I will take a look to the link you provide – gofr1 May 23 '16 at 06:36

3 Answers3

1

I would suggest using tools like copperegg or Uptime Robot

There are plenty more solutions out there.And it's a waste of time and resources to implement a script of your own.

Gayan Hewa
  • 2,277
  • 4
  • 22
  • 41
  • Thanks for your answer, in one way it is truly waste of resources, but is very interesting to do it myself, on the other side working solutions and tools like you suggested will do this job better. I will take a look on links and tools you suggested. – gofr1 May 23 '16 at 06:39
1

I would suggest you to run this check via cron and store the status in a mysql table. You can set the cron to run every minute. Update status after each check. At users end, simply fetch the status of servers from MySQL database. In such a way, you will be solving any timeout issues also as well as you will be able to fetch status of the servers quickly from db.

Rehmat
  • 4,681
  • 3
  • 22
  • 38
  • Thanks for your input, I'm not familiar with cron (heard, but never used) I will check if it is useful for my task. – gofr1 May 23 '16 at 06:37
  • @gofr1 you must check and use cron for tasks like this as this will automate your script. – Rehmat May 23 '16 at 06:49
0

Most simple way is to run update status job with cron, and store the results somewhere in local file or db.

And then you just need to fetch the results and show it to the client.

Valentin
  • 89
  • 2