PHP performance hampered by require()

前端 未结 5 574
旧时难觅i
旧时难觅i 2021-01-19 18:25

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 a

相关标签:
5条回答
  • 2021-01-19 18:38

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

    Such compiler makes everything work faster, also including files.

    0 讨论(0)
  • 2021-01-19 18:39

    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 
    
    0 讨论(0)
  • 2021-01-19 18:45

    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.

    0 讨论(0)
  • 2021-01-19 18:47

    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.

    0 讨论(0)
  • 2021-01-19 18:47

    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.

    0 讨论(0)
提交回复
热议问题