PHP filemtime 函数 - “统计失败”
我的 PHP filemtime 函数有问题。在我的网络应用程序中,我使用带有缓存选项的 Smarty 模板引擎。在我的网络应用程序中,我可以执行一些会产生错误的操作,但让我们只关注一个操作。当我单击页面上的链接时,某些内容会更新 - 我可以单击几次,一切正常,但大约 10 上的一个请求失败。出现以下错误:
filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for
以及导致问题的行:
return ($_template->getCachedFilepath() && file_exists($_template->getCachedFilepath())) ? filemtime($_template->getCachedFilepath()) : false ;
如您所见,文件存在,因为它已被检查。
有问题的代码行包含在 smarty_internal_cacheresource_file.php
(Smarty lib v3.0.6 的一部分)中
应用程序在 UNIX 系统、外部托管上运行。
有什么想法吗?我应该发布更多详细信息吗?
I have a problem with PHP filemtime function. In my webapp I use Smarty template engine with caching option. In my webapp I can do some actions which generate error, but lets focus on only one action. When I click link on page some content is updated - I can click few times and everything is OK but about one request on 10 fails. Following error occurs:
filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for
and the line that causes the problem:
return ($_template->getCachedFilepath() && file_exists($_template->getCachedFilepath())) ? filemtime($_template->getCachedFilepath()) : false ;
As you can see, file exists because it is checked.
Problematic line of code is included in smarty_internal_cacheresource_file.php
(part of Smarty lib v3.0.6)
App is run on UNIX system, external hosting.
Any ideas? Should I post more details?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
file_exists
内部使用access< /code>
系统调用检查真实用户的权限,而
filemtime
使用stat
,执行检查为有效用户。因此,问题的根源可能在于有效用户==真实用户的假设并不成立。另一种解释是该文件在两次调用之间被删除。由于
$_template->getCachedFilepath()
的结果和文件的存在情况都可能在系统调用之间发生变化,为什么要调用file_exists
呢?相反,我建议如果
$_template->getCachedFilepath()
可以设置为虚拟值,例如false
,请使用以下内容:file_exists
internally uses theaccess
system call which checks permissions as the real user, whereasfilemtime
usesstat
, which performs the check as the effective user. Therefore, the problem may be rooted in the assumption of effective user == real user, which does not hold. Another explanation would be that the file gets deleted between the two calls.Since both the result of
$_template->getCachedFilepath()
and the existance of the file can change in between system calls, why do you callfile_exists
at all? Instead, I'd suggest justIf
$_template->getCachedFilepath()
can be set to a dummy value such asfalse
, use the following:使用:
阅读此和这个
Use:
Read this and this
我多年来一直成功地使用 filemtime 而不检查“file_exists”。我一直解释文档的方式是,出现任何错误时都应从“filemtime”返回 FALSE。然后几天前发生了一件非常奇怪的事情。如果该文件不存在,我的 Cron 作业就会终止。结果不在程序输出中,而是在 Cron 输出中。该消息是“文件长度超出”。我知道 Cron 工作在 filemtime 语句上结束,因为我在该语句之前和之后给自己发送了一封电子邮件。 “之后”的电子邮件从未到达。
我在文件上插入了 file_exists 检查来修复 Cron 作业。然而,这本来是没有必要的。我仍然不知道我使用的托管服务器上发生了什么变化。其他几个 Cron 作业在同一天开始失败。我还不知道它们是否与 filemtime 有关。
I used filemtime successfully without checking "file_exists" for years. The way I have always interpreted the documentation is that FALSE should be returned from "filemtime" upon any error. Then a few days ago something very weird occurred. If the file did not exist, my Cron job terminated with a result. The result was not in the program output but rather in the Cron output. The message was "file length exceeded". I knew the Cron job ended on the filemtime statement because I sent myself an email before and after that statement. The "after" email never arrived.
I inserted a file_exists check on the file to fix the Cron job. However, that should not have been necessary. I still do not know what was changed on the hosting server I use. Several other Cron jobs started failing on the same day. I do not know yet whether they have anything to do with filemtime.