开发者

CPU load with file_exists in php

i o开发者_高级运维wn 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?


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


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜