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.

 Live Demo

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

Output

Cache cleared!

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

167 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements