In PHP is

Source: Internet
Author: User
Tags sleep sleep function

  The first question to ask is, can is_file really replace file_exists? The answer is in the negative. Why? The reason is simple, is_file has a cache

We can use the following code to test: The code is as follows: <?php         $filename = ' test.txt ';       if (Is_file ($filename)) {          echo "$filename exists!n";      } else {          echo "$filename no exists!n";      }     &NB Sp Sleep (10);      if (Is_file ($filename)) {          echo "$filename exists!n";      } else {          echo "$filename no exists!n";      }?> when we run the test code, we do Paul Test.txt file exists. In the code above, the first time you use the Is_file function to determine if a file exists, and then call the sleep function for 10 seconds. In this 10 seconds, we will remove the Test.txt file. Finally look at the result of the second call to the Is_file function. The output results are as follows: Test.txt exists! Test.txt exists! Well, you are not wrong, two are output "Test.txt exists!", this is why? The reason is that Is_file has a cache. The first time that you call the Is_file function, PHP saves the file's properties (STAT), and when you call Is_file again, if the filename is the same as the first time, the cache is returned directly. 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 use the test method above to test again. The results are as follows: Test.txt exists! Test.txt No exists! Second call FIle_exists when the return file does not exist, this is because the file_exists function is not cached, no time to call File_exists will go to the disk search file exists, so the second will return false. Said so much, I just want to explain is_file can not replace file_exists use, if you just feel is_file performance is good, then I have no way    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.