Bug #80695 [Com]: Extremely slow PHP file access operations on all Windows OS's
| From: | beberlei@php.net | Date: | Mon, 01 Feb 2021 19:57:18 +0000 |
| Subject: | Bug #80695 [Com]: Extremely slow PHP file access operations on all Windows OS's | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231875@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80695&edit=1
ID: 80695
Comment by: beberlei@php.net
Reported by: info at futurion dot si
Summary: Extremely slow PHP file access operations on all
Windows OS's
Status: Open
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Windows (All platforms)
PHP Version: 7.4.14
Block user comment: N
Private report: N
New Comment:
Just to clarify, the stat cache is only a *single* entry cache, storing the stat information of the
last file that was accessed. So that explains why clearstatcache before/after example makes no
difference.
Previous Comments:
------------------------------------------------------------------------
[2021-02-01 19:54:25] info at futurion dot si
Description:
------------
I did some extensive tests on various PHP versions on windows and linux platforms. Long story short,
it seems windows suffer big time from slow file-access with all PHP file-related functions. I used
as a sample a simple PHP script, which is published here:
https://pastebin.com/VfLCgs3K
That script takes about 10x or more time on windows in comparison to linux. I tried all possible
combinations (power profiles, opcache, safe mode, windows defender and firewall disable, wincache,
etc.), but it doesn't matter, nothing helps. I also tried different windows versions, different
web servers, also running that script in CLI is slow as well.
That above being said, would you be maybe kind enough to look into this issue, or maybe try running
that same script at your side as well and maybe write something useful back. Is there actually any
way to gain some "speed" on windows to be at least close to linux's performance? I
really can't believe PHP on windows is so much slower than on linux.
Kind regards and thank you in advance for your answer.
Tomaz Kavcic.
Test script:
---------------
<?php
$microtime = microtime(true);
function displayCounter($txt){
global $microtime;
echo "<p> {$txt}: ". round((microtime(true) - $microtime) * 1000,0)
."ms</p>";
$microtime = microtime(true);
}
$file_prefix = __DIR__ . '/file';
for($i= 1; $i < 1000; $i++){
file_put_contents($file_prefix . $i, '');
}
displayCounter('File Creation');
for($i= 1; $i < 1000; $i++){
file_exists($file_prefix . $i);
}
displayCounter('file_exists');
clearstatcache();
for($i= 1; $i < 1000; $i++){
file_exists($file_prefix . $i);
}
displayCounter('file_exists (after cache clear)');
for($i= 1; $i < 1000; $i++){
unlink($file_prefix . $i);
}
displayCounter('unlink');
Expected result:
----------------
Tested on Ubuntu Linux 20.04 (Apache 2)
-
File Creation: 33ms
file_exists: 4ms
file_exists (after cache clear): 4ms
unlink: 22ms
Teset on Ubuntu Linux 20.04 (PHP CLI)
-
File Creation: 20ms
file_exists: 2ms
file_exists (after cache clear): 2ms
unlink: 11ms
Actual result:
--------------
Tested on Windows 2019 Server (Also on other Windows OS's - similar results)
-
File Creation: 104ms
file_exists: 21ms
file_exists (after cache clear): 20ms
unlink: 62ms
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80695&edit=1