PHP filemtime 函数 - “stat failed for" [英] PHP filemtime function - "stat failed for"

查看:174
本文介绍了PHP filemtime 函数 - “stat failed for"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 PHP filemtime 函数有问题.在我的 webapp 中,我使用带有缓存选项的 Smarty 模板引擎.在我的 web 应用程序中,我可以执行一些会产生错误的操作,但让我们只关注一个操作.当我点击页面上的链接时,一些内容会更新 - 我可以点击几次,一切正常,但大约 10 个请求失败.出现以下错误:

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.

有问题的代码行包含在 smarty_internal_cacheresource_file.php(Smarty lib v3.0.6 的一部分)中

Problematic line of code is included in smarty_internal_cacheresource_file.php (part of Smarty lib v3.0.6)

应用在 UNIX 系统上运行,外部托管.

App is run on UNIX system, external hosting.

有什么想法吗?我应该发布更多详细信息吗?

Any ideas? Should I post more details?

推荐答案

file_exists 内部使用 access 系统调用以真实用户的身份检查权限,而filemtime使用 stat,它执行以有效用户的身份进行检查.因此,问题可能源于有效用户==真实用户的假设,该假设不成立.另一种解释是文件在两次调用之间被删除.

file_exists internally uses the access system call which checks permissions as the real user, whereas filemtime uses stat, 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.

既然 $_template->getCachedFilepath() 的结果和文件的存在都可以在系统调用之间改变,那么你为什么要调用 file_exists?相反,我建议只是

Since both the result of $_template->getCachedFilepath() and the existance of the file can change in between system calls, why do you call file_exists at all? Instead, I'd suggest just

return @filemtime($_template->getCachedFilepath());

如果可以将 $_template->getCachedFilepath() 设置为一个虚拟值,例如 false,请使用以下内容:

If $_template->getCachedFilepath() can be set to a dummy value such as false, use the following:

$path = $_template->getCachedFilepath();
if (!$path) return false;
return @filemtime($path);

这篇关于PHP filemtime 函数 - “stat failed for"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆