Nate,
To find the 'ping' time (or equivalent), you can use the microtime function. For example, lets say you are connecting to http protocol using fsockopen; then do:
$starttime = microtime();
fsockopen($host, $port);
$endtime = microtime();
// Microtime output is: "microseconds actualseconds"
$parts_of_starttime = explode(" ", $starttime);
$starttime = $parts_of_starttime[0] + $parts_of_starttime[1];
$parts_of_endtime = explode(" ", $endtime);
$endtime = $parts_of_endtime[0] + $parts_of_endtime[1];
$ping_time = $endtime - $starttime;
The $ping_time results in the time taken to establish the socket connection. This may be a bit better than ping because ping gives you the seconds it took to contact the host using icmp protocol.
If you want to time FTP protocol, replace the fsockopen with ftp_connect.
About file sizes:
- For http, if you get the first 512 bytes of the file (after doing GET /whatever HTTP/1.0), then most servers return the line: "Content-length: xxxbytes". You can search for this line and parse it. If it doesn't exist... then I don't know any other way!
- For FTP, there is the ftp_size command. Use it with ftp_connect file descriptor.
hope this helps,
Sridhar
Nate wrote:
Is there a way to ping a server through php? This is for a download script so I would like users to be able to see how fast the server is at the moment. Right now I don't really need it to be more than one server, but in the near future that will change.
Also, can you find the size of a file?