2. http://www.emanueleferonato.com/2006/05/31/determine-connection-speed-with-php/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$kb=512;
echo "streaming $kb Kb...<!-";
flush();
$time = explode(" ",microtime());
$start = $time[0] + $time[1];
for($x=0;$x<$kb;$x++){
echo str_pad('', 1024, '.');
flush();
}
$time = explode(" ",microtime());
$finish = $time[0] + $time[1];
$deltat = $finish - $start;
echo "-> Test finished in $deltat seconds. Your speed is ". round($kb / $deltat, 3)."Kb/s";
?>
Done. Analysis and considerations:
2: Declaring how much Kb I want to transmit to accomplish the test. This value can also be passed in POST or GET. In my example it is
declared.
3: I write I am downloading data, and open a comment tag. Everithing I am sending from now on will not be displayed. It’s not necessary, but
prevents the browser to be fullfilled of chars.
4: Flush the chache
5-6: Saving actual timestamp
7-9: For $kb times I send 1024 chars (1Kb) and flush the cache
11-12: Saving actual timestamp
13: Calculating difference between start and finish timestamps
14: Closing comment tag and writing test result, calculated as Kb/time
Done… very easy isn’t it?
5. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$kb=512;
echo "streaming $kb Kb...<!-";
flush();
$time = explode(" ",microtime());
$start = $time[0] + $time[1];
for($x=0;$x<$kb;$x++){
echo str_pad('', 1024, '.');
flush();
}
$time = explode(" ",microtime());
$finish = $time[0] + $time[1];
$deltat = $finish - $start;
echo "-> Test finished in $deltat seconds. Your speed is ". round($kb / $deltat, 3)."Kb/s";
?>
서버의 아웃풋을 내는 성능이
무한대라고 볼 때,
그래서 순간 아웃풋을 발생시킨다고 할 때,
전송한 데이터 / 걸린 시간
위 방법으로 클라이언트의 전송속도를 알 수 있다?
6. 내 생각에는 위 코드는
서버의 성능을 나타내는 것일 뿐이지,
‘클라이언트’ 또는 ‘클라이언트-서버’ 간의 인터넷 속도를
나타내지 못할 거 같다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$kb=512;
echo "streaming $kb Kb...<!-";
flush();
$time = explode(" ",microtime());
$start = $time[0] + $time[1];
for($x=0;$x<$kb;$x++){
echo str_pad('', 1024, '.');
flush();
}
$time = explode(" ",microtime());
$finish = $time[0] + $time[1];
$deltat = $finish - $start;
echo "-> Test finished in $deltat seconds. Your speed is ". round($kb / $deltat, 3)."Kb/s";
?>
Php의 Backend에,
flush를 통한 출력이 어떻게 처리되는지를
이해해야지, 명확히 알 수 있을 거 같다.
7. Apache http web server의 경우,
다양한 서버사이드 언어를 모듈을 달아서 만질 수 있는데,
php의 경우 mod_php가 그것이다.
적어도 Apache에서 PHP를 돌리는 방법은 두가지가 있다.
CGI와 mod_php
14. GET 요청은 QUERY_STRING 환경변수로 데이터를 넘기는 것이군.
CGI 프로그램에 클라이언트가 보낸 데이터를 보낸다.
데이터는 웹 양식 form 이고, 이렇게 보내는 걸 POST라 한다.
CGI 프로그램의 STDIN으로 전달한다. 전달하는 형식은 위와 같다.
그 형식이 종종 URL 뒤에 붙기도 하는데, 그런 경우는
이런 문자열을 유용한 정보로 처리해야 하겠네. 그런 라이브러리와 모듈이 있구나.