Detailed explanation of the use of php clearstatcache() function

怪我咯
Release: 2023-03-13 12:54:02
Original
1543 people have browsed it

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()
Copy after login

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"); 
    ?>
    Copy after login
    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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!