PHP clearstatcache()ฟังก์ชั่น
❮ การอ้างอิงระบบไฟล์ PHPตัวอย่าง
ขนาดไฟล์เอาต์พุต ตัดทอนไฟล์ ล้างแคช แล้วจึงส่งออกขนาดไฟล์อีกครั้ง:
<?php
//output filesize
echo filesize("test.txt");
echo "<br />";
$file = fopen("test.txt", "a+");
// truncate file
ftruncate($file,100);
fclose($file);
//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
ผลลัพธ์ของโค้ดด้านบนอาจเป็น:
792
100
ความหมายและการใช้งาน
ฟังก์ชัน clearstatcache() จะล้างแคชสถานะไฟล์
PHP แคชข้อมูลสำหรับฟังก์ชันบางอย่างเพื่อประสิทธิภาพที่ดีขึ้น หากต้องตรวจสอบไฟล์หลายครั้งในสคริปต์ คุณอาจต้องการหลีกเลี่ยงการแคชเพื่อให้ได้ผลลัพธ์ที่ถูกต้อง เมื่อต้องการทำเช่นนี้ ให้ใช้ฟังก์ชัน clearstatcache()
ไวยากรณ์
clearstatcache(clear_realpath_cache, filename)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
clear_realpath_cache | Optional. Indicates whether to clear the realpath cache or not. Default is FALSE, which indicates not to clear realpath cache |
filename | Optional. Specifies a filename, and clears the realpath and cache for that file only |
เคล็ดลับและหมายเหตุ
เคล็ดลับ:ฟังก์ชันที่กำลังแคช:
- สถิติ ()
- lstat()
- แฟ้มที่มีอยู่()
- is_writable()
- is_readable()
- is_executable()
- is_file()
- is_dir()
- is_link()
- filectime()
- เวลาไฟล์ ()
- filemtime()
- fileinode()
- กลุ่มไฟล์()
- เจ้าของไฟล์ ()
- ขนาดไฟล์()
- ประเภทไฟล์ ()
- fileperms()
รายละเอียดทางเทคนิค
คืนมูลค่า: | ไม่มีอะไร |
---|---|
รุ่น PHP: | 4.0+ |
บันทึกการเปลี่ยนแปลง PHP: | PHP 5.3 - เพิ่มพารามิเตอร์ทางเลือกสองตัว: clear_realpath_caheและ filename |
❮ การอ้างอิงระบบไฟล์ PHP