0

c# では、ダウンロード速度を確認するために webclient を使用してファイルを文字列としてダウンロードしますが、javascript または PHP でこれを行うにはどうすればよいですか? これが私のc#サンプルです。

  Uri URL = new Uri("https://www.example.com/File512kb");
  WebClient wc = new WebClient();
  double starttime = Environment.TickCount;
  string file = wc.DownloadString(URL);     //download this file as string so I won't need to save it to local disk.
  stopWatch.Elapsed.Milliseconds;
  double endtime = Environment.TickCount;
  double milisecs = endtime - starttime;

ありがとう...

4

4 に答える 4

1

100%正確ではありませんが、PHPで使用できfile_get_contents()ますmicrotime()

http://us3.php.net/file_get_contents http://us1.php.net/manual/en/function.microtime.php

于 2012-12-05T15:33:23.350 に答える
1
$fStart = microtime( true );

file_get_contents( 'http://www.example.com/File512kb' );

$fEnd = microtime( true );

echo $fEnd - $fStart;
于 2012-12-05T15:34:42.847 に答える
1

PHPでこれを行う方法は次のとおりです。

<?php

    set_time_limit(0);
    $start_time = microtime(true);
    $file = file_get_contents('http://somefileorother.com/file');
    $end_time = microtime(true) - $start_time;

    echo $end_time; 
于 2012-12-05T15:35:37.413 に答える
1

JavaScript:

var start = new Date();
$.ajax({
    url: "https://www.example.com/File512kb"
}).done(function() {
    console.log(new Date() - start);
});

経過時間をミリ秒単位で返します。ただし、関数は jQuery を使用します。これは、AJAX 呼び出しを作成するための非常に簡単な方法だからです。

于 2012-12-05T15:36:02.613 に答える