Bug->Doc #78285 [Ver]: file_exists is 30 times slover than is_dir

From: Date: Mon, 15 Jul 2019 17:06:22 +0000
Subject: Bug->Doc #78285 [Ver]: file_exists is 30 times slover than is_dir
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16822@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78285&edit=1 ID: 78285 Updated by: cmb@php.net Reported by: video dot ice dot power at seznam dot cz Summary: file_exists is 30 times slover than is_dir Status: Verified -Type: Bug +Type: Documentation Problem Package: *Directory/Filesystem functions Operating System: Windows 10 PHP Version: 7.3.7 -Assigned To: cmb +Assigned To: Block user comment: N Private report: N New Comment: Actually, it is to be expected that file_exists() is much slower than is_dir() (when the realpath cache is enabled), because the former checks whether the file may be accessed, and since this information is not cached, it is done for each and every call. Changing to doc problem, since this behavior is not described in the manual. Previous Comments: ------------------------------------------------------------------------ [2019-07-15 09:49:40] cmb@php.net <?php $t0 = hrtime(true); for ($i = 0; $i < 1000; $i++) { is_dir(__DIR__); } $t1 = hrtime(true); for ($i = 0; $i < 1000; $i++) { file_exists(__DIR__); } $t2 = hrtime(true); printf("is_dir took %f ms\n", ($t1 - $t0)/10e6); printf("file_exists took %f ms\n", ($t2 - $t1)/10e6); outputs for me something like: is_dir took 0.051130 ms file_exists took 3.395850 ms ------------------------------------------------------------------------ [2019-07-13 20:13:22] video dot ice dot power at seznam dot cz Description: ------------ file_exists() is 30 times slover than is_dir() Test script: --------------- for ($i = 0; $i < 1000; $i++) { is_dir('some path to directory'); } // 0.5ms for ($i = 0; $i < 1000; $i++) { file_exists('some path to directory'); } // 15 ms Expected result: ---------------- The file_exists method should run in about the same time as the is_dir method does. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78285&edit=1

« previous php.doc.bugs (#16822) next »