clearstatcache() function in PHP

PHPProgrammingServer Side Programming

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!
raja
Published on 03-Oct-2018 12:00:48
Advertisements