Checking network speed with PHP / Javascript

I am trying to find a way to check network speed using PHP or Javascript.

Is it possible?

I would like to test the speed and dynamically decide how much content to deliver to the client ...

I should point out that I'm mostly talking about mobile devices. Most broadband connections are very different from each other, so I'm trying to assess if someone is connected to a Wi-Fi network or is fighting for a cellular network.

+6
source share
2 answers

Make an ajax request to load a fixed-size data block and check the time before / after to get an approximate idea of ​​speed:

var start = new Date(); $.ajax(....); var end = new Date(); var elapsed = end.getTime() - start.getTime(); // elapsed time in milliseconds. 

You will need to use a large enough piece of data to get valid queries, which means that you are wasting enough bandwidth for this test only.

+2
source

As I see it, you can use JS -> PHP -> JS call and response time, but this is pretty inaccurate. In addition, you will need to use enough data (excessive bandwidth usage) and will never get an explicit answer due to server headers that exist / do not exist between browsers. There are also worries about service providers (comcast cough cough), where they give you 12 Mbps for the first few seconds, but then put you down to 3mbits, so now your β€œTest” will say that they are on the OC line, but the stream is now will have a data deficit and is constantly buffered.

The best solution is to build the logic in the stream protocol, which can be adjusted depending on how much / small data comes in. Perhaps it starts with low quality bandwidth and raises the bar when it notices that the buffer grows faster than the data plays (this is what Hulu, YouTube or Amazon videos do).

+1
source

Source: https://habr.com/ru/post/893720/


All Articles