Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need change file_exists to is_file? #1543

Closed
ytetsuro opened this issue Nov 27, 2018 · 1 comment
Closed

need change file_exists to is_file? #1543

ytetsuro opened this issue Nov 27, 2018 · 1 comment

Comments

@ytetsuro
Copy link
Contributor

I think would need strict check file when want file.

And, is_file is faster than file_exists.

In CodeIgniter, the file_exists function is used at the place where you are requesting a file.
I would like to change this to use the is_file function.
Shall I make RR?

your want that change?

https://github.com/codeigniter4/CodeIgniter4/search?q=file_exists&unscoped_q=file_exists

benchmark PHP7.1

<?php

touch('dummy');
$start = microtime(true);
for($i = 0; $i < 10000; $i++) {
file_exists('dummy');
}
echo (microtime(true) - $start)."\n";                                           

$start = microtime(true);
for($i = 0; $i < 10000; $i++) {
is_file('dummy');
}
echo (microtime(true) - $start)."\n";

0.0363450050354
0.0103449821472

@natanfelles
Copy link
Contributor

Yes. Check with is_file where only a file is wanted.

file_exists also returns true if the filename is a directory, this is not wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants