PHP Clearstatcache () function use detailed

Source: Internet
Author: User
The Clearstatcache () function clears the file state cache.

PHP caches the return information of some functions in order to provide higher performance. But sometimes, for example, if you check the same file multiple times in a script and the file is at risk of being deleted or modified during the execution of the script, you need to clear the file state cache to get the correct results. To do this, use the Clearstatcache () function.

Grammar

Clearstatcache ()

Hint: a function that will be cached, that is, the function affected by the Clearstatcache () function:

    • Stat ()

    • Lstat ()

    • File_exists ()

    • Is_writable ()

    • Is_readable ()

    • Is_executable ()

    • Is_file ()

    • Is_dir ()

    • Is_link ()

    • Filectime ()

    • Fileatime ()

    • Filemtime ()

    • Fileinode ()

    • Filegroup ()

    • Fileowner ()

    • FileSize ()

    • FileType ()

    • Fileperms ()

The sample code for the Clearstatcache () function is as follows:

<?php//check filesize Echo filesize ("test.txt"); echo "<br/>"; $file = fopen ("Test.txt", "A +"); Truncate file Ftruncate ($file, 100); Fclose ($file);//clear cache and check filesize againcle arstatcache (); echo filesize ("test.txt");?>

The code above will output the following result:
792

100

Related Article

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.