Clearstatcache in PHP

Source: Internet
Author: User
Tags lstat
The clearstatcache () function is used to clear the File status cache.

PHP cache data is very advantageous for faster and better function running. If a file is tested in a script

After multiple attempts, you may not cache the correct results. To achieve this, you can use

Clearstatcache () function.

When Stat (), lstat (), or any function column in the affected function table (see the following figure) is used,

PHP will cache the returned information of these functions to provide faster performance. However, in some cases, you may

To clear the cached information. For example, if the same file is checked multiple times in a script

When this script is executed, you need to clear the File status cache when it is deleted or modified. This situation

You can use the clearstatcache () function to clear the file information cached by PHP.

Note that PHP does not cache the information of non-existing files. So if you call

File_exists () to check for non-existing files. Before the file is created, it will return

False. If the file is created, true is returned even if it is deleted later.

Note: This function caches the information of a specific file name. Therefore, it only performs operations on the same file name multiple times and

Clearstatcache () is called only when the file information is not cached ().

Syntax

Clearstatcache ()

Tips and notes

Tip: Execute the cache function:

Stat ()

Lstat ()

File_exists ()

Is_writable ()

Is_readable ()

Is_executable ()

Is_file ()

Is_dir ()

Is_link ()

Filectime ()

Fileatime ()

Filemtime ()

Http://www.ibwen.com love blog provides massive data to meet your thirst for knowledge!

All resources on this site are reprinted from the internet! Copyright owned by the author

Http://www.ibwen.com

Fileinode ()

Filegroup ()

Fileowner ()

Filesize ()

Filetype ()

Fileperms ()

Case

<? PHP

// Check filesize

Echo filesize ("test.txt ");

Echo "<br/> ";

$ File = fopen ("test.txt", "A + ");

// Truncate File

Ftruncate ($ file, 100 );

Fclose ($ file); // clear cache and check filesize againcle

Arstatcache ();

Echo filesize ("test.txt ");

?>

The above code will output the following results:

792

100

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.