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: Open
-Type: Bug
+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:
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".
Previous Comments:
------------------------------------------------------------------------
[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