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



我接触了WINDOWS IIS6 PHP服务器配置,从我的测试来看,文件读取速度真的很差。

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

我用读取文件和 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硬盘并将应用程序移动到该驱动器上并为您带来更大的收益可能会少得多。

如果这不是一个选项,你最好使用 IIS 本身来提供静态文件,比如 X-Sendfile:

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

另一种选择可能是安装像APC这样的opcache,它也在Windows上可用。

这将减少从 FS 读取的内容,因为文件存储在内存中(正确安装时)。

其次,您可以将CMS存储在虚拟硬盘上,因此整个代码将保存在内存中,并且每个文件的访问时间将最小化。

最新更新