In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "Why is_file can not be used instead of file_exists in PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
We can test it with the following code:
The copy code is as follows:
When running the test code, we make sure that the test.txt file exists. In the above code, the is_file function is used for the first time to determine whether the file exists, and then the sleep function is called to sleep for 10 seconds. In these 10 seconds, we have to delete the test.txt file. Finally, take a look at the result of the second call to the is_file function. The output is as follows:
Test.txt exists!
Test.txt exists!
Well, you read it correctly. Both times you output "test.txt exists!". Why is that? The reason is that is_file has a cache. The first time the is_file function is called, PHP saves the file stat of the file, and when is_file is called again, if the file name is the same for the first time, it will directly return to the cache.
What about changing is_file to file_exists? We can change the is_file function of the above code to the file_exists function and test it again using the above test method. The results are as follows:
Test.txt exists!
Test.txt no exists!
The return file does not exist when file_exists is called the second time, because the file_exists function does not have cache, and every time file_exists is called, it will go to disk to search for the existence of the file, so false will be returned the second time.
Having said that, I just want to make it clear that is_file cannot be used instead of file_exists.
This is the end of the introduction to "Why can't you replace file_exists with is_file in PHP?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.