Have it connect to a server you know runs fast (such as Google). Then, measure how long it takes from sending the first packet to receiving the first packet - that's your upload time. The time from receiving the first to last packets is the download time. Then divide by the amount of data transferred and there's your result.
Example:
$times = Array(microtime(true));
$f = fsockopen("google.com",80);
$times[] = microtime(true);
$data = "POST / HTTP/1.0\r\n"
."Host: google.com\r\n"
."\r\n"
.str_repeat("a",1000000); // send one megabyte of data
$sent = strlen($data);
fputs($f,$data);
$firstpacket = true;
$return = 0;
while(!feof($f)) {
$return += strlen(fgets($f));
if( $firstpacket) {
$firstpacket = false;
$times[] = microtime(true);
}
}
$times[] = microtime(true);
fclose($f);
echo "RESULTS:\n"
."Connection: ".(($times[1]-$times[0])*1000)."ms\n"
."Upload: ".number_format($sent)." bytes in ".(($times[2]-$times[1]))."s (".($sent/($times[2]-$times[1])/1024)."kb/s)\n"
."Download: ".number_format($return)." bytes in ".(($times[3]-$times[2]))."s (".($return/($times[3]-$times[2])/1024)."kb/s)\n";
(You will get an error message from Google's servers, on account of the Content-Length
header missing)
Run it a few times, get an average, but don't run it too much because I don't think Google would like it too much.