PHP ダウンロード file_put_contents と readfile

WBOY
リリース: 2016-07-28 08:27:51
オリジナル
1419 人が閲覧しました

set_time_limit(0);
ini_set('memory_limit', '512M');
//获取当前時間间
function getTime($convert = true)
{
return microtime($convert);
}
//获取当前内存
関数memory()
{
returnmemory_get_usage();
}
$m =memory();
$s = getTime();
$file = file_get_contents("a.zip", true);
header(" Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: " . filesize('a.zip'));
header('Content-性質: 添付ファイル; filename="a.zip"');
echo $file;
error_log('file_put_contents: 内存:'.(memory()-$m).',消費時間:'.(getTime()- $s).'rn',3,'D:/1.txt');
/* readfile() ベンチマーク */
$m = Memory();
$s = getTime();
ob_start();
header('Content-Type: application/octet-stream');
header("Accept-Range: bytes");
header("Accept-Length: " . filesize('a.zip'));
header ('Content-Disposition:attachment; filename="a.zip"');
header('Content-Transfer-Encoding:binary');
readfile('a.zip');
ob_end_clean();

error_log ('readfile: 内存:'.(memory()-$m).',所要時間:'.(getTime()-$s).'rn',3,'D:/1.txt');

結果如下:

2k文件
file_put_contents: 内部存続期間: 2304, 所要時間: 0.00099992752075195
readfile: 内部存続期間: 0.00200009346 0083
20M文件
file_put_contents: 内存存数:50126256、所要時間:0.21602201461792
readfile: 内存存数:896 、所要時間:0.071007013320923
153M 文件
file_put_contents: 内部存続期間: 321370872、所要時間: 1.0341031551361
readfile: 内部存続期間: 1.942 1939849854

结论:同じ条件下で大文書をダウンロードするときにreadfileを使用して更省内に存在し、不php 内に存在するオーバーフローが発生しやすいです。

以上は、PHP のダウンロード file_put_contents と readfile の比較であり、側面のコンテンツも含まれており、PHP 教則に関心のある友人の助けになることを望んでいます。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!