Current Location: Home> Function Categories> clearstatcache

clearstatcache

Clear file status cache
Name:clearstatcache
Category:File system
Programming Language:php
One-line Description:Clear the file status cache.

Definition and usage

clearstatcache() function clears the file state cache.

The clearstatcache() function caches the return information of certain functions to provide higher performance. But sometimes, for example, if you check the same file multiple times in a script, and the file is in danger of being deleted or modified during execution of this script, you need to clear the file status cache to get the correct results. To do this, you need to use the clearstatcache() function.

A function that will be cached, that is, a function that is affected by 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()

Example

 <?php
//Check file size
echo filesize ( "test.txt" ) ;

$file = fopen ( "test.txt" , "a+" ) ;

// Intercept the file
ftruncate ( $file , 100 ) ;
fclose ( $file ) ;

//Clear cache and check file size again
clearstatcache ( ) ;
echo filesize ( "test.txt" ) ;
?>

Output:

 792
100

grammar

 clearstatcache ( )
Similar Functions
  • Determine whether the given file name is a symbolic connection is_link

    is_link

    Determinewhethertheg
  • Get the inode of the file fileinode

    fileinode

    Gettheinodeofthefile
  • Modify the owner of the symbolic link lchown

    lchown

    Modifytheownerofthes
  • Determine whether the file exists and is readable is_readable

    is_readable

    Determinewhetherthef
  • Write to files (safely used in binary files) fwrite

    fwrite

    Writetofiles(safelyu
  • Create a new directory mkdir

    mkdir

    Createanewdirectory
  • Obtain file permissions fileperms

    fileperms

    Obtainfilepermission
  • Find file paths that match patterns glob

    glob

    Findfilepathsthatmat