views:

261

answers:

5

I ran my code through xdebug profiler and saw more than 30 percent of the time is spent on the require() calls. What is the best way to improve on this? I saw some posts about using __autoload, but there were conflicting statements about it's affect on APC (which we use), and doubts about it's use to improve performance.

+3  A: 

The reason why requires consume time is disk IO speed. You can try using autoloading, as you may be requiring files that aren't actually used. Another approach to reduce the disk IO overhead is to combine your PHP files into one large file. Requiring a big file which contains the code you always need is faster than including the same code in multiple small files.

Also, APC has a feature which speeds up requires called apc.include_once_override which you can try enabling.

Jani Hartikainen
are you referring to apc.stat ?
bob
It's apc.include_once_override
Jani Hartikainen
A: 

how many items are in your include path? and is the order of the locations sensible for your application? if you're using relative paths then it will check the include-path locations in order looking for a matching file.

Greg
+1  A: 

Make sure your includes use absolute instead of relative paths. Easiest way to do this is by prepending your paths with

dirname(__FILE__)  // for php < 5.3
__DIR__            // for php >= 5.3
Werner
+1  A: 

You can improve speed of your code by using PHP compiler, like http://eaccelerator.net/.

Such compiler makes everything work faster, also including files.

Thinker
A: 

APC and autoload had some problems once. That's a long time ago. In general, APC can speed up you require statements, since it caches the parsed files. By default APC will still stat the file to see if it has changed on disk. You can prevent this by using absolute paths and turning the apc.stat setting off. Note that this means that you have to restart the server to clear the cache.

troelskn