Home  >  Article  >  Backend Development  >  Detailed explanation of the use of php clearstatcache() function

Detailed explanation of the use of php clearstatcache() function

怪我咯
怪我咯Original
2017-07-10 16:29:501540browse

clearstatcache() function clears the file status cache.

PHP will cache the return information of some functions to provide higher performance. But sometimes, such as when you check the same file multiple times in a script and the file is in danger of being deleted or modified during the execution of the script, you need to clear the file status cache in order to get the correct results. To do this, use the clearstatcache() function.

Syntax

clearstatcache()

Tips: Functions that perform caching, that is, functions 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
  • ( )

  • ##clearstatcache() function example code 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 above code will output the following results:

792100

The above is the detailed content of Detailed explanation of the use of php clearstatcache() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn