PHP Clearstatcache-Clear the file state cache _php Tutorial

Source: Internet
Author: User
Tags lstat
About PHP Clearstatcache-Clear the File status cache below we have explained, there are specific examples oh.

Clearstatcache
(PHP 4, PHP 5)
Clearstatcache-Clears the file state cache
Describe
Invalid Clearstatcache ([Boolean $ clear_realpath_cache = False [, string $ file name]])
When you use statistics (), Lstat (), or any other function listed in the list of affected features (below), PHP caches information to restore these functions to provide faster performance. However, in some cases, you may want to clear the cache information. For example, if the same file is being checked multiple times in a script, the file is dangerous to delete or change in the script's run, you can choose to clear the cache status. In this case, you can use the Clearstatcache () function to clear the information that PHP caches about the file.
You should also notice that PHP does not cache files that do not exist for the information. Therefore, if you require that the file on file_exists () does not exist, it will return false until you create the file. If you create a file, it is returned even if you then delete the file. However, disconnecting () automatically clears the cache.
Note: This feature caches information about the specific file name, so you only need to call Clearstatcache () if you are engaged in a variety of businesses in the same file name and ask about that particular file not being cached.
The affected features include statistics (), Lstat (), file_exists (), is_writable (), is_readable (), is_executable (), Is_file (), Is_dir (), Is_link (), Filectime (), Fileatime (), Filemtime (), Fileinode (), archive Group (), Fileowner (), File size (), document type (), and fileperms ().
Parameters
Clear_realpath_cache
Whenever the cache is cleared or not Realpath (the default is False).
Filename
Explicitly realpath the specific file name of the cache, if only using Clear_realpath_cache is true.
return value
No return of value.
Modify
Release Notes
5.3.0 time optional clear_realpath_cache and filename parameters.
Instance
Example # 1 Clearstatcache () example

$file = ' output_log.txt '; function Get_owner ($file) {    $stat = stat ($file);    $user = Posix_getpwuid ($stat [' uid ']);    return $user [' name '];} $format = "UID @%s:%sn";p rintf ($format, date (' R '), Get_owner ($file)), Chown ($path, ' Ross ');p rintf ($format, date (' R '), Get_owner ($file)); Clearstatcache ();p rintf ($format, date (' R '), Get_owner ($file));? >

Output

UID @ Sun, Oct 20:48:28 +0100:rootuid @ Sun, Oct 20:48:28 +0100:rootuid @ Sun, Oct 2008 20:48:28 +010 0:ross
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.