Edit report at https://bugs.php.net/bug.php?id=64510&edit=1
ID: 64510
User updated by: gu_ludo at yahoo dot com dot br
Reported by: gu_ludo at yahoo dot com dot br
Summary: filemtime() and 'mtime' index from stat() only works
for the first call
Status: Wont fix
Type: Feature/Change Request
Package: Filesystem function related
Operating System: WinXP SP3
PHP Version: 5.3.23
Block user comment: N
Private report: N
New Comment:
Ok, so I'll will respect the consensus.
Just one question: May I use fstat() to non-cached stats, or it is likely to
this
function behave like stat() in the future?
Previous Comments:
------------------------------------------------------------------------
[2013-03-25 15:01:35] [email protected]
We had a few discussions about this and the general consensus is that stats
should by default be cached. Running scripts without stat cache can often
result in a quite significant performance hit. The cases where you need
non-cached stats are rather rare and certainly don't justify adding a slowdown
for all other calls.
------------------------------------------------------------------------
[2013-03-25 14:03:02] gu_ludo at yahoo dot com dot br
I found out that there's the function clearstatcache()
(http://php.net/manual/en/function.clearstatcache.php), which solves the
problem.
Although, I think the "affected functions" listed on the documentation page
should return by default the actual values and the caching could be optionally
configured. So I change this bug's type to "Change request".
------------------------------------------------------------------------
[2013-03-25 13:46:10] gu_ludo at yahoo dot com dot br
Description:
------------
The functions stat() and filemtime() don't return a different value for the
file's modification time on a second call whereas fstat() does.
Test script:
---------------
echo "Using filemtime():\n";
$filename = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($filename, "First row\n", FILE_APPEND);
var_dump(filemtime($filename));
sleep(5);
file_put_contents($filename, "Second row\n", FILE_APPEND);
var_dump(filemtime($filename));
echo "\nUsing stat():\n";
$filename = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($filename, "First row\n", FILE_APPEND);
$stat = stat($filename);
var_dump($stat['mtime']);
sleep(5);
file_put_contents($filename, "Second row\n", FILE_APPEND);
$stat = stat($filename);
var_dump($stat['mtime']);
echo "\nUsing fstat():\n";
$filename = tempnam(sys_get_temp_dir(), 'foo');
$f = fopen($filename, 'r');
file_put_contents($filename, "First row\n", FILE_APPEND);
$stat = fstat($f);
var_dump($stat['mtime']);
sleep(5);
file_put_contents($filename, "Second row\n", FILE_APPEND);
$stat = fstat($f);
var_dump($stat['mtime']);
Expected result:
----------------
Using filemtime():
int(1364217934)
int(1364217939)
Using stat():
int(1364217939)
int(1364217944)
Using fstat():
int(1364217944)
int(1364217949)
Actual result:
--------------
Using filemtime():
int(1364217934)
int(1364217934)
Using stat():
int(1364217939)
int(1364217939)
Using fstat():
int(1364217944)
int(1364217949)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64510&edit=1