A
A
awikong2018-06-02 23:20:28
PHP
awikong, 2018-06-02 23:20:28

How to update dynamic data received via UDP?

Good evening. I'm learning PHP MySQL, I've only just started.
For experience, I decided to develop server monitoring. You need to train somewhere.
Essence:
20 servers are displayed on the page.
When a user enters the site, information about 20 servers is simultaneously received via UDP directly, without caching, etc. Refreshes the page again with fresh data. Because of this, the page takes a very long time to load, especially if the server is located somewhere in the USA.
I came to the conclusion that you need to somehow store the data in the database. Let's say every minute. And on the full information page of the server, you can also display information with a direct request, because one server will load faster.
Here is the part of the array that I get:

Array
(
    [Protocol] => 17
    [HostName] => Panda-Community.com #16 | 2Fort
    [Map] => ctf_2fort
    [ModDir] => tf
    [ModDesc] => Panda-2Fort
    [Players] => 24
    [MaxPlayers] => 24
    [Bots] => 0
    [Dedicated] => d
    [Os] => l
    [Password] => 
    [Secure] => 1
    [Version] => 4516743
    [ExtraDataFlags] => 177
    [GamePort] => 27165
    [SteamID] => 85568392920041083
    [GameTags] => respawntimes,alltalk,2fort,anime,best,best ping,brony,community,ctf,ctf_2fort,eu,fastdl,gametracker,panda,panda community,panda
    [GameID] => 440
)

On the general page, I only need to indicate data about:
[HostName] => Panda-Community.com #16 | 2Fort
 [Map] => ctf_2fort
 [Players] => 24
 [MaxPlayers] => 24
 [GameID] => 440

That's exactly 5 lines I'm going to save in the database and output via MySqli to the page and not via UDP and so on.
Please point me, how can I do that once a minute, for example, for all servers in the database, the data for these 5 fields is updated for me.
Where to dig, maybe there are examples?
I apologize if I wrote something that was not technically correct. I'm just learning and trying to solve the problem. Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kisaa, 2018-06-03
@kisaa

Since you understand that you are writing a training bike, look at an existing monitoring system like zabbix. Briefly, its structure is as follows: a separate monitoring server is executed, which polls the hosts at a specified frequency, and adds the results to the database. And a web-muzzle is executed separately, which takes data from this database and displays them in accordance with the established filters.

S
Saboteur, 2018-06-04
@saboteur_kiev

1. A separate script periodically queries the servers and updates the data in the database. The user receives data only from the database.
2. You can cache requests.
For example, when querying the status of a specific server, you save data about this server and the time of the request to the local database.
On the next request, you check how long ago the request was made to the server. If more than xx minutes ago - repeat the request to the server. If less - take the cached data from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question