php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26011 filemtime-problem
Submitted: 2003-10-27 16:09 UTC Modified: 2003-10-27 17:32 UTC
From: final at solnet dot ch Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.3 OS: SuSE Linux 8.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: final at solnet dot ch
New email:
PHP Version: OS:

 

 [2003-10-27 16:09 UTC] final at solnet dot ch
Description:
------------
ok, i've written a "watcher-tool" for my /var/log/mail, which is a syslog-file (for pop-before-smtp with sendmail, but this doesn't matter). i have a never ending do-while with a sleep of 4 seconds, and i use filemtime to see if something changed in /var/log/mail. well, the problem was, the script never went through even if the file got changed (i've checked that with ls -l many times...). only if you get filemtime of another file between two filemtimes of /var/log/mail, php noticed that the file modification time changed.

well, but if you edit the file by an editor, php does notice it. first i thought, its a matter of syslog-daemon, but since i tried to use filemtime on another file between two checks of /var/log/mail, im not sure anymore...

Reproduce code:
---------------
#!/usr/local/php/bin/php
<?php
$file = "/var/log/mail";
$filemtime = filemtime($file);
do
{
	sleep(3);
	echo "not out yet!";
} while (filemtime($file) == $filemtime);
// you'll never get out, even if the log-file gets changed :)
echo "im out (but this will never happen :p)";
?>

Expected result:
----------------
Get out of do ... while as soon as sendmail/postfix/qpopper/ipopd/whatever writes something to your /var/log/mail

Actual result:
--------------
you won't get out :p

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-27 17:32 UTC] iliaa@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

stat() calls, which filemtime uses internally are cached for performance reasons. Therefor you should use clearstatcache() before each filemtime() call to clear the cache.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 11:01:34 2025 UTC