PHP Speed ​​Test for user connection speed without echo on the current page

I am looking for an opportunity to check the connection speed with the user. It is assumed that it will be saved as cookies and javascript, as well as css files will be adapted if the speed is slow.

The ability to check the speed that I currently have is as follows

    $kb = 512;

    flush();
    //
    echo "<!-";
    $time = explode(" ",microtime());
    for($x=0;$x<$kb;$x++){
        echo str_pad('', 512, '.');
        flush();
    }
    $time_end = explode(" ",microtime());
    echo "->";

    $start = $time[0] + $time[1];
    $finish = $time_end[0] + $time_end[1];
    $deltat = $finish - $start;

    return round($kb / $deltat, 3);

While it works, I do not like to insert so many codes into my code, and if I repeat all this, I can not save the result in a cookie, because there was already an exit.

Is it possible to do something like this in another file? Do you have a solution?

Thanks in advance.

+5
source share
7 answers

Do you have a solution?

, . :

, , , JS/CSS . , ( ). , 256 . , , , , 512 ?

, . MBs JS/CSS ( , ), . , ..

+6

, , - .

, , , .

+3

, , , , PHP. , , (512x512) = 262 144 , , . , , ( 10 /, , - !).

AJAX , . , , .

(, GMail ), , (, , , ).

" " cookie AJAX, - ; , , 10 , .

; .

+1

javascript , . javascript cookie.

microtime javascript http://phpjs.org/functions/microtime:472

jQuery

<head>
<!-- include jquery & other html snipped -->

<script>

function microtime (get_as_float) {
    // http://kevin.vanzonneveld.net
    // +   original by: Paulo Freitas
    // *     example 1: timeStamp = microtime(true);
    // *     results 1: timeStamp > 1000000000 && timeStamp < 2000000000

    var now = new Date().getTime() / 1000;
    var s = parseInt(now, 10);

    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}

function setCookie(c_name, value, expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

start = microtime(true);

$(window).load(function () {
  // everything finished loading
  end = microtime(true);
  diff = end - start;
  // save in a cookie for the next 30 days

    setCookie('my_speed_test_cookie', diff, 30);
});

</script>
</head>
<body>
<p>some page to test how long it loads</p>
<img src="some_image_file.png">
</body>

: - . JQuery ( , jQuery)

  • ASCII/ , . gzip , / ( ) , , 500 . , ,
+1

(, 100 ), $ _SESSION [ "start_time" ] = time();

( jQuery smth:) u , u (jQueryRequestTime - $_SESSION [ "start_time" ]/PageSize) , , , css/js,

ofc :)

+1

, , javascript , cookie, , , .

0

, , - , IP- . IP- . , . IP- , .

Ip2Location.com ​​ , DB13.

, - , .

0

All Articles