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
Popular Articles