Clearstatcache in PHP

Source: Internet
Author: User
Tags lstat
This article to share the content is about PHP Clearstatcache, has a certain reference value, the need for friends can refer to

The function of the

clearstatcache () function is to clear the file state cache. The
PHP cache data is advantageous for faster and better running functions. If a file is tested
multiple times in a script, you may disallow caching of the correct results. To achieve this, you can use the
Clearstatcache () function.
When you use Stat (), Lstat (), or any of the functions listed in the affected function table (see below),
PHP caches the return information for these functions to provide faster performance. In some cases, however, you might
want to clear the cached information. For example, if you check the same file multiple times in a script and the file is at risk of being deleted or modified during the execution of the
script, you need to clear the file state cache. In this case
, you can use the Clearstatcache () function to clear the file information that is cached by PHP. The
must be aware that PHP does not cache its information for files that do not exist. So if you call
File_exists () to check for a nonexistent file, it returns
FALSE before the file is created. If the file is created, it will return TRUE if it is later deleted
Note: This function caches information for a specific file name, so you need to call Clearstatcache () only if you have multiple operations on the same file name and
require that the file information not be cached.
Syntax
Clearstatcache ()
Hints and notes
Prompt: Functions that perform caching:
stat ()
Lstat ()
file_exists ()
is_writable ()
Is_readable ()
is_executable ()
Is_file ()
Is_dir ()
Is_link ()
Filectime ()
Fileatime ()
Filemtime ()
Http://www.ibwen.com Ebowen provides a huge amount of information to satisfy your curiosity!
All resources of this site are reproduced from the internet! Copyright by author all
Http://www.ibwen.com
Fileinode ()
Filegroup ()
Fileowner ()
FileSize ()
filetype ()
Fileperms ()
Case

<?php//check filesizeecho filesize ("test.txt"); echo "<br/>"; $file = fopen ("Test.txt", "A +");//Truncate Fileftruncate ($file, +), fclose ($file),//clear cache and check filesize againclearstatcache (); Echo FileSize (" Test.txt ");? >

The code above will output the following result:
792
100

Related recommendations:

PHP Clearstatcache () function use detailed

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.