touchしてもstat cacheはクリアされない
touch()を実行したらそのPHPプロセスにとってメタ情報が変わったことは明らかだ。なのでclearstatcache()しなくてもfilemtime()の値が新しくなると思い込んでいたのだが、実際はそうではない。
7.0b2のソースでもそのようなコードはない。
// ext/standard/filestat.c PHP_FUNCTION(touch) { ... ret = VCWD_UTIME(filename, newtime); ... } // Zend/zend_virtual_cwd.h (抜粋) #ifdef VIRTUAL_DIR #define VCWD_UTIME(path, time) virtual_utime(path, time) #else #ifdef ZEND_WIN32 #define VCWD_UTIME(path, time) win32_utime(path, time) #else #define VCWD_UTIME(path, time) utime(path, time) #endif #endif
実際に試してみても新しい修正日は取得できない。
<?php define('TARGET', __FILE__); $orig = filemtime(TARGET); sleep(1); touch(TARGET); var_dump($orig == filemtime(TARGET)); // bool(true) = 未更新 clearstatcache(false, TARGET); var_dump($orig == filemtime(TARGET)); // bool(false)
効率のためにそういう仕様なのだろう。