I'm trying to find out a way to test network speed using PHP or Javascript.
Is this possible?
I'd ideally like to test the speed and the dynamically decide how much content to deliver to the client...
I should point out i'm largely talking about mobile devices. Most broadband connection differ very little so i'm aiming to gauge whether someone is connected to a WiFi network or is struggling on Cellular data network.
The connection_status() function returns the current connection status. Possible values that can be returned are: 0 - CONNECTION_NORMAL - connection is running normally. 1 - CONNECTION_ABORTED - connection is aborted by user or network error.
Speedtest® CLI With Speedtest CLI, you can easily: Measure internet connection performance metrics like download, upload, latency and packet loss natively without relying on a web browser.
Visit http://www.speedtest.net/ to test the upload and download speed of your IP connections and identify your public IP address.
Do an ajax request to download a fixed-size chunk of data and check the time before/after to get a rough idea of speeds:
var start = new Date();
$.ajax(....);
var end = new Date();
var elapsed = end.getTime() - start.getTime(); // elapsed time in milliseconds.
You'd need to use a large enough chunk of data to get valid requests, which'd mean you're wasting a fair amount of bandwidth just to do this test.
They way I see it, you can use JS -> PHP -> JS call and time the response, but that is pretty inaccurate. Also, you'd need to use a fair amount of data (excess bandwidth usage concerns) and would never get an explicit answer due to server headers that exist/don't exist between browsers. There's also a concern with service providers (cough comcast cough) where they give you 12 mbit speeds for the first few seconds, but choke you down to 3mbits afterward, so now your "Test" would say they're on an OC line but the stream itself would now have a data deficit and be buffering constantly.
The best solution is to build the logic in to the streaming protocol that can adjust based on how much/little data is coming in. Maybe it starts out at a low bandwidth quality and raises the bar when it notices the buffer is growing faster than the data is playing (this is what Hulu, YouTube or Amazon video do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With