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