gpt4 book ai didi

php - 如何提高 IIS PHP 服务器上的读取文件速度?

转载 作者:可可西里 更新时间:2023-11-01 10:46:49 27 4
gpt4 key购买 nike

我接触了 WINDOWS IIS6 PHP 服务器配置,从我的测试来看,文件读取速度非常糟糕。

对于 300000 字节以下的文件,我的读取速度为 0.89 秒到 1.8 秒。将其与相同代码返回 0.017752170562744 秒的速度的 Linux 服务器设置进行比较

我测试了 readfile 和 fopen。

我应该在 php 配置或服务器配置中查看或设置什么,以便读取速度可以接受。

这是我用来测试的代码

//updated
$file = '../assets/cache/siteCache.idx.php';

$time_start = microtime(true);
readfile($file);
$time_end = microtime(true);

$time2 = $time_end - $time_start;
echo $file . ': ' . filesize($file) . ' bytes' . '<hr />';
echo "Time to read with readfile: $time_end - $time_start = $time2 seconds<hr />";

$time_start = microtime(true);
$handle = fopen($file, "r");
fclose($handle);
$time_end = microtime(true);

$time1 = $time_end - $time_start;
echo $file . ': ' . filesize($file) . ' bytes' . '<hr />';
echo "Time to read with fopen: $time_end - $time_start = $time1 seconds<hr />";

最佳答案

查看您正在使用的软件 API 的物理磁盘可能会有更好的进展。

较旧或较便宜的硬盘驱动器可能具有较慢的寻道时间和较低的吞吐量。安装一个快速的 SSD 硬盘并将您的应用程序移动到该驱动器上并为您带来更大的 yield 可能会少很多工作。

如果这不是一个选项,您最好使用 IIS 本身使用 X-Sendfile 之类的东西来提供您的静态文件:

https://github.com/stakach/IIS-X-Sendfile-plugin

关于php - 如何提高 IIS PHP 服务器上的读取文件速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20889406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com