php 中 file_exists 的 CPU 负载

发布于 2024-08-17 02:05:29 字数 81 浏览 8 评论 0原文

我拥有一个每分钟 cpu httpd 请求负载很高的网站。我注意到我在每个 httpd 请求上使用“file_exists”。这个功能是不是太重了?

i own a site with a high load cpu httpd request per minute. I've noticed i use "file_exists" on each httpd request. Is that function to much heavy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风流物 2024-08-24 02:05:29

此函数只会检查文件是否存在 - 这意味着对磁盘的访问(可能需要一点时间,但也不会花太多时间)

考虑到您的应用程序可能由数十个组成(如果不是数百个) 个 PHP 文件,每个请求都必须读取这些文件,我认为一个 file_exists 没有任何区别。

(嗯,至少,只要您检查本地磁盘上的文件 - 不通过任何网络驱动器或类似的东西)

旁注:如果您想确定 PHP 脚本中的 CPU 消耗情况,您可能会对 Xdebug 扩展,它提供了分析功能。

您可以阅读我不久前给出的这个答案,它很长: 我如何测量用 php 编写的代码的速度? -- 我不会在这里复制粘贴它。

您可能还想阅读我对该问题的回答(我在其中写了有关 Xdebug 和分析的部分):优化基于 Kohana 的网站以提高速度和可扩展性

This function will only check of a file exists -- which means an access to the disk (which might take a little time, but not that much either)

Considering your application is probably made of dozens (if not hundreds) of PHP files, which all have to be read for each request, I don't think one file_exists makes any difference.

(Well, at least, as long as your are checking for a file on a local disk -- not going through any network drive or anything like that)

As a sidenote : if you want to identify where CPU is spend in your PHP scripts, you might be interested by the Xdebug extension, which provides a profiling functionnality.

You can read this answer I gave some time ago, which is quite long : How can I measure the speed of code written in php? -- I won't copy-paste it here.

You might also want to read my answer to that question (there is a section where I wrote about Xdebug and profiling) : Optimizing Kohana-based Websites for Speed and Scalability

如何视而不见 2024-08-24 02:05:29

现实地说,玩“猜测瓶颈”可能是一项相当徒劳的任务 - 我建议使用分析器,例如 Zend Studio

Being realistic, playing 'guess the bottleneck' is likely to be a pretty fruitless task - I'd recommend using a profiler, such as the one built into Zend Studio.

孤独患者 2024-08-24 02:05:29

file_exists 通常非常便宜,特别是因为结果缓存在 php 的统计缓存.. 像重型数据库这样的领域往往是 cpu 的最大消耗者。

尝试进行一些分析来确定应用程序的哪一部分使用时间最多,这里有一些示例:

http://www.ibm.com/developerworks/opensource/library/os-php-fastapps2/

file_exists is typically very cheap, especially since the result is cached in php's stat cache.. areas like heavy DB tend to be the largest consumer of cpu.

try some profiling to determine what part of your app is using up the most time, some examples here:

http://www.ibm.com/developerworks/opensource/library/os-php-fastapps2/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文