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
  • Read the entire file into an array file

    file

    Readtheentirefileint
  • Get the file owner fileowner

    fileowner

    Getthefileowner
  • Synchronize changes to files (including metadata) fsync

    fsync

    Synchronizechangesto
  • Determine whether the file exists and is readable is_readable

    is_readable

    Determinewhetherthef
  • Read files (safely used in binary files) fread

    fread

    Readfiles(safelyused
  • alias for disk_free_space diskfreespace

    diskfreespace

    aliasfordisk_free_sp
  • Format input from a file fscanf

    fscanf

    Formatinputfromafile
  • Return to the directory part in the path dirname

    dirname

    Returntothedirectory