Search code examples
phpprofilerxdebugrequire-once

PHP / xdebug profiler require_once poor performance


I just started using xdebug to profile my application and immediately noticed something strange in the results. One of the require_once functions is shown to be taking around 12% of the processing time. There are quite a few other calls to require_once throughout the application and they're all taking less than 1% of the processing time.

The poorly-performing require_once is including a file that's not significantly different or larger than any of the other files, so I'm not sure what could be causing the problem. Has anybody else ever experienced something like this?

Edit: Wanted to provide a little more info. I'm doing the profiling on windows using XAMPP. Normally the application runs on a unix box. I haven't got an easy way to get xdebug onto the box, so it may not be feasible for me to try and compare the results that way.

One last edit: Here's an idea of the code in case that helps (intentionally being vague for the standard CYA legal reasons blah blah blah):

This class is the one with the slow include (test.inc):

require_once('/xx/yy/zz/dao/basedao.inc');
require_once('/xx/yy/zz/vo/test.inc');

class TestDAO extends BaseDAO {
  // bunch of code to handle database records and return VO objects

And this is the file being included:

require_once('/xx/yy/zz/vo/basevo.inc');

class Test extends BaseVO {
  // bunch of properties, getters/setters, that kinda stuff

I have quite a few other VO/DAO objects that are built the exact same way, without any issue. All are located within the same respective paths.


Solution

  • That does indeed sound odd. Definitely worth pursuing, though it'll be hard to work it out for sure without seeing the actual code. 12% of the total program time for a single require_once() does sound very excessive.

    But here are some thoughts on possible avenues of investigation:

    1. require_once() keeps a lookup table of files that have been included, so perhaps it's slowing things down having to refer to that lookup table. If this is the cause, you could solve it by using require() rather than require_once() wherever possible.

    2. Perhaps it's the path lookup? Are you including a path with the filename? If not, it'll be checking in a number of places to find the file; perhaps it isn't in the first place it looks, it'll be taking longer to find the file before it can include it. If this is the cause, you could solve it by being more specific about the path in your code.

    Hope that helps. Would be interested to hear how this pans out.

    Oh, and by the way -- if your biggest problem area in your code is require_once(), then it sounds like you've done a good job with your code! I dream of the day require_once() even shows up in my profiler reports, let alone with an significant effect.