php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36189 filemtime()
Submitted: 2006-01-28 10:57 UTC Modified: 2006-01-28 14:22 UTC
From: aemulus at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.1.2 OS: Fedora Core 3
Private report: No CVE-ID: None
 [2006-01-28 10:57 UTC] aemulus at hotmail dot com
Description:
------------
When reading in a file modified timestamp, then writing to the file, if you read the modified timestamp right after closing the file, it shows the same modification stamp.

Reproduce code:
---------------
$downloadfile = 'http://www.somewebservice.com/stat.xml';
$filename = 'somefile.txt';
$data = geturlfile($downloadfile,2);
if (file_exists($filename)) {
echo "filemtime1: ".date("F d Y H:i:s.",filemtime($filename));
}
$cont=fopen($filename,'w');
$didwrite = fwrite($cont,$data);
fclose($cont);
print "<br>Written: ".$didwrite."<br>";
if (file_exists($filename)) {
echo "filemtime2: " . date ("F d Y H:i:s.", filemtime($filename));
}

//functions
function geturlfile($link2,$timeout) {
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$link2);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)) {
return "0";
} else {
return $buffer;
}
}

Expected result:
----------------
Both timestamps will be identical for "filemtime1" and "filemtime2"

Actual result:
--------------
filemtime1: January 28 2006 04:44:49.
Written: 9996
filemtime2: January 28 2006 04:44:49.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-28 14:22 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is because PHP employs a cache for this, use clear_stat_cache() and it will work fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC