Computer >> Computer tutorials >  >> Programming >> PHP

clearstatcache() function in PHP


The clearstatcache() function clears the file status cache.

PHP caches the information returned by the following functions −

  • stat()
  • lstat()
  • file_exists()
  • is_writable()
  • is_readable()
  • is_executable()
  • is_file()
  • is_dir()
  • filegroup()
  • fileowner()
  • filesize()
  • filetype()
  • fileperms()

This is done to provide enhanced performance.

Syntax

void clearstatecache()

Parameters

  • NA

Return

No value is returned by the clearstatcache() function.

Example

The following is an example that checks for file “tmp.txt” and clears cache.

<?php
   $file = fopen("tmp.txt", "a+");
   // Clear cache
   clearstatcache();
   echo "Cache cleared!";
?>

Output

Cache cleared!