PHP real-time Get file size

Source: Internet
Author: User
Tags flock

To write a large data to a file, but do not want to write a file, want to be written as a document XM, you need to determine the file size in real time, if you do not clean the file state cache, can not achieve the effect.


The Clearstatcache () function clears the file state cache.

The Clearstatcache () function caches the return information of some functions in order to provide higher performance. But sometimes, 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 to get the correct results. To do this, you need to use the Clearstatcache () function.

Functions that are cached, that is, those that are affected by the Clearstatcache () function:

      • Stat ()
      • Lstat ()
      • File_exists ()
      • Is_writable ()
      • Is_readable ()
      • Is_executable ()
      • Is_file ()
      • Is_dir ()
      • Is_link ()
      • Filectime ()
      • Fileatime ()
      • Filemtime ()
      • Fileinode ()
      • Filegroup ()
      • Fileowner ()
      • FileSize ()
      • FileType ()
      • Fileperms ()
1 //information is stored in files, 2m per file,2$max _size =1024x768*1024x768*2;3 4$v = Str_repeat ('Hello', - );5 6$tmp _i =1;7$handler =NULL;8                 //foreach (Dinfo::galldoclisthandle ()->each () as $v) {9                  for($i =0; $i <=100000; $i + + ){Ten                     if(Is_null ($handler)) { One$handler = fopen ($file _path,'AB' ); A Flock ($handler, lock_ex); -                     } -  the$tmp _val = Json_encode ($v)."\ r \ n"; -Fwrite ($handler, $tmp _val, Mb_strlen ($tmp _val,'UTF8' )  ); - Clearstatcache (); -  +                     if(FileSize ($file _path) >=$max _size) { - Flock ($handler, lock_un); + fclose ($handler); A$handler =NULL; at$file _path = $cache _dir.'Alldoc.'. $tmp _i++.'. txt'; -                     } -}

PHP real-time Get file size

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.