Php, is_dir, is_file, file_exists obviously file_exists is affected by asp, because asp not only has fileExists but also folderExists and driverExists, then file _
Php, is_dir, is_file, file_exists
Obviously, file_exists is affected by asp, because asp not only has fileExists but also folderExists and driverExists. what does file_exists in PHP mean?
File_exists = is_dir + is_file in PHP
It can determine whether a file exists and whether a directory exists, but such a comprehensive function execution efficiency is very low, just as the request in asp does not specify form or get, cookies, so the conclusion is:
To determine whether a directory exists, use the independent function is_dir (directory). to determine whether a file exists, use the independent function is_file (filepath)
Is_file only checks whether the file exists;
File_exists checks whether the file exists or whether the directory exists;
Is_dir: determines whether a directory exists;
Check the manual. although the results of both functions are cached, the is_file speed is N times faster. Note that when a file exists, is_file is N times faster than file_exists. if the file does not exist, is_file is slower than file_exists;
Conclusion:The file_exits function does not affect the speed because the file actually exists, but the is_file function has a big impact. I have understood the differences between file_exists and is_file and is_dir in PHP, file_exists = is_dir + is_file of PHP.
Write a program to verify,Execute 1000 times, record the required time, the code is as follows, the file exists (current directory)
- Is_file: 0.4570 ms
- File_exists: 2.0640 ms
- File exists (absolute path layer 3/www/hx//)
- Is_file: 0.4909 ms
- File_exists: 3.3500 ms
- File exists (absolute path layer 5/www/hx/a/B/c /)
- Is_file: 0.4961 ms
- File_exists: 4.2100 ms
- File does not exist (current directory)
- Is_file: 2.0170 ms
- File_exists: 1.9848 ms
- File does not exist (absolute path layer 5/www/hx/a/B/c /)
- Is_file: 4.1909 ms
- File_exists: 4.1502 ms
- Directory exists
- File_exists: 2.9271 ms
- Is_dir: 0.4601 ms
- The directory does not exist.
- File_exists: 2.9719 ms
- Is_dir: 2.9359 ms
- Is_file ($ file)
- File_exists ($ file)
When $ file is a directory, is_file returns false, and file_exists returns true. if the file exists, is_file is much faster than file_exists. the deeper the directory where the file is located, the more the speed difference, but at least four times faster. If the file does not exist, is_file is a little slower than file_exists, but it is negligible. If a directory exists, is_dir is much faster than file_exists. if a directory does not exist, is_dir is a little slower than file_exists, but can be ignored.
Conclusion:If you want to determine whether a file exists, use the is_file () function. if you want to determine whether a directory exists, use the is_dir () function. it seems that file_exists is not needed, are you sure you want to use the input parameters in a file or directory?