PHP performance is hampered by requirement ()

I ran my code through the xdebug profiler and saw that more than 30% of the time is spent on require () calls. What is the best way to improve this? I saw several reports about the use of __autoload, but the APC (which we use) made conflicting statements about this, and doubts about its use to improve performance.

+4
source share
5 answers

The reason it takes time to consume is disk I / O speed. You can try using autoload, as you may need files that are not actually used. Another approach to reduce IO overhead on disk is to merge your PHP files into one large file. Requiring a large file that contains the code you always need is faster than including the same code in several small files.

In addition, APC has a function that speeds up the apc.include_once_override call, which you can try to enable.

+4
source

Make sure your application uses an absolute value instead of relative paths. The easiest way to do this is to add your paths with

dirname(__FILE__) // for php < 5.3 __DIR__ // for php >= 5.3 
+2
source

You can improve the speed of your code with a PHP compiler, for example http://eaccelerator.net/ .

Such a compiler makes everything faster, including files.

+1
source

APC and startup had some problems. This is a long time. In general, APC can speed up the execution of require statements because it caches the parsed files. By default, APC will still have a stat file to see if it has changed on disk. You can prevent this by using absolute paths and disabling apc.stat . Note that this means that you need to restart the server to clear the cache.

+1
source

how many elements are in your inclusion path? and is the location order reasonable for your application? if you use relative paths then it will check the include-path locations to find the corresponding file.

0
source

All Articles