Help you look at the snippet code
PHP Code
$filename = ' test.txt '; $data = file_get_contents ($filename); $fsize = FileSize ($filename)/1024x768; $start = time (); echo "
"; $stop = time (); $duration = $stop-$start; $speed = Round ($fsize/$duration, 2); echo "Your network speed: $speed kb/s";
The book said that this code can calculate network bandwidth, I tried to find no, $start and $stop are equal. Think about it, $duration calculate the time that the PHP engine parses the Echo statement, not the time the user receives $data. Think again, if you want to calculate the bandwidth, you have to calculate the user gets the HTML file time, but that is after the PHP parsing is done, it is not possible to use PHP to calculate the user bandwidth is not the case?? Please correct me, ask for the realization of calculating user's bandwidth
------Solution--------------------
Put $stop = time (); Move to the front
Your code detects the speed at which the file is read
Continue to
$filename assignment to a remote file name
FileSize ($filename) to strlen ($data)
Your code detects the bandwidth of your server.
Only PHP is not able to detect user bandwidth
There must be client collaboration, roughly as follows
The client issues a test request (onsubmit) while recording and issuing the time the request occurred
PHP outputs a fixed-size content after a request is received and logs the time that the client sent (thus calculating the client's upstream time)
In the client's onload event, the current time is given to PHP again
PHP gets down time after deduction of upstream time
And then.....