views:

174

answers:

3

Hi, 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?

+5  A: 

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

Pascal MARTIN
+1 for the profiler pointer - your edit beat me to it. :-)
middaparka
@middaparka : Thanks :-) ;; after answering, I thought "why not give more informations", and started searching in some old answers I gave (I remembered having given some long answers about xdebug ^^ )
Pascal MARTIN
+1  A: 

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/

jspcal
+2  A: 

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.

middaparka