If I run the following command through the terminal:
wget --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" WEBSITEURL.COM -O TestFile.html
I get a file with the contents of the page at WEBSITEURL.COM. The file is desired, however, I would also like to get 1) file size and 2) elapsed download time put into variables.
I can get the file with PHP using the following:
$getFile = exec("wget --user-agent=\"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3\" $url -O Downloaded-$url.html");
The file size I can easily get but it's the elapsed download time to get that file in the first place that's eluding me.
Perhaps there's a better option than wget I might use...?
答案 0 :(得分:0)
这有效:
<?php
$loadInstance = new LoadFileFromHTML();
echo "Duration:".$loadInstance->loadFileAndGetTime( "your-file", "http://www.google.com" );
class LoadFileFromHTML
{
public function loadFileAndGetTime( $fileName, $fromUrl )
{
$aCurlOptions = array(
CURLOPT_URL => $fromUrl,
CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3",
CURLOPT_RETURNTRANSFER => 1,
);
$curlInstance = curl_init();
curl_setopt_array($curlInstance, $aCurlOptions);
$start = microtime( TRUE );
$returnedData = curl_exec($curlInstance);
$duration = microtime( TRUE ) - $start;
curl_close($curlInstance);
file_put_contents( $fileName, $returnedData );
return $duration;
}
}
?>
注意:
CURL
选项中解决SSL证书问题。它以秒为单位返回所需的时间。