Hi all,
I want to make upload test (bandwidth test) for my project.
How my program work is like this :
first, reading data from server and save it to buffer
code to store data to buffer:
function getdata($data,$kbytes)
{
if($fd=fopen($data,"rb"))
{
$rf=fread($fd,$kbytes*1024);
ob_start();
echo "<!-- $rf -->";
$buffer=ob_get_contents();
ob_end_clean();
return $buffer;
fclose($fd);
}
else
{
echo "Could not read data";
}
}
second, send this data to server through ftp
code to data send to ftp :
function sendfile($ftppath,$sitepath,$savef,$putfile)
{
extract($GLOBALS);
$page1="$ftppath/$savef";
$page2="$sitepath/$savef";
$server="server";
$username="user";
$password="pass";
$ftp=ftp_connect($server) or die("Invalid Server");
$conn=ftp_login($ftp,$username,$password);
$fp=fopen($page2,"w");
fputs($fp,("$putfile"));
fclose($fp);
ftp_quit($ftp);
return true;
}
to get time value, im using this code :
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
To calculate bandwidth time. im using this formula :
total time=endtime-starttime.
speed=data/totaltime
kbps=((speed1024)8)/1000;
my question is :
- after i tried many times i still didnt get the correct result.
- any ideas?