help with some php to test router connection

Teddyz

Occasional Visitor
Reason for this question is that I think my AX88U is no good and _sometimes_ gives me bad wifi-connections. But do not focus on that. :)

I have an Apache/php server on my lan. What I want is a webpage on that server that when I connect to it, it will continuously exchange data with my android phone browser. At least a few packets per second so I in real-time can see that the wifi-link is working. I am not interested in testing speed, just that the connection is okay.
Do you have a link to some php that could do this or similar?
Thanks!
 

ColinTaylor

Part of the Furniture
Any reason it has to be web traffic? A continuous ping ought to keep the connection alive.
 

Teddyz

Occasional Visitor
The reason I want web traffic, is that I have tried ping via an app called Fing. Fing makes some 30 rapid pings and shows the result on a graph. I don't trust it, because all failed pings are shown as the first one or two of the 30, never number 15 or so. I wish that function of Fing would be possible to configure. (And I guess that there are other apps that would keep pinging, more like how I want it.

I guess that there is a difference between the many ICMP-packets and one TCP connection.

I pasted some code below that in the best worlds would do both ping and keep a connection to the server. Problem is that it will not display the progress, but instead all the rows when finished.

PHP:
<?php
$num = 0;
header( 'Content-type: text/html; charset=utf-8' );
echo ("test of connection<br>"); //<-- send this to the client

while($num < 16 ) {
    $num++;
    echo ($num . ": ");
    echo ping ("192.168.1.1");
    echo "<br>";
    ob_flush();
    flush();
    usleep ( 100000 ); // pause 100ms between the pings
}


function ping($host, $timeout = 1) {
    /* ICMP ping packet with a pre-calculated checksum */
    $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
    $socket  = socket_create(AF_INET, SOCK_RAW, 1);
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
    socket_connect($socket, $host, null);
    $ts = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
        $result = microtime(true) - $ts;
    } else {
        $result = false;
    }
    socket_close($socket);
    return $result;
}

?>
 

Teddyz

Occasional Visitor
The code above is no good, here is a shorter/better version that works for me. When I have been connected to 2.4GHz WiFi for a longer period, this code shows that I have a bad connection. If I disconnect from my RT-AX88U and reconnects, it is smooth again. I wonder why.

Link to my server: testconn.php

PHP:
<html>
<head>
  <title>testconn</title>
</head>
<body>
<p>
<?php
// ob_end_flush();
// ob_implicit_flush();
ob_end_clean();
$num = 0;
echo("testing that a slow constant flow<br> of data is smooth through wifi<br>");
while($num++ < 240) { // max number depends on pause length and web server settings
  if ( ($num % 30) == 0) {echo " " . $num/2 . "s<br>";}
  else if ( ($num % 2) == 0) {echo "\\";}
  else {echo "/";}
  ob_flush();
  flush();
  usleep ( 500000 ); // pause 500ms between each dot
}
echo("done<br>"); //<-- send this to the client
?>
</p>
<button style="height:50px;width:150px;" onClick="window.location.reload();">again</button>
</body>
</html>

Chrome/Firefox on my phone changes formatting after more than a minute. Would like to know why. Any suggestions for improvements are of course welcome.
 

Teddyz

Occasional Visitor
Safari does not show anything until the whole page is loaded. :( But it is useful for Firefox and Chrome,
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top