简体   繁体   English

PHP / xdebug profiler require_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. 我刚开始使用xdebug来分析我的应用程序,并立即发现结果中有些奇怪的东西。 One of the require_once functions is shown to be taking around 12% of the processing time. 其中一个require_once函数显示占用了大约12%的处理时间。 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. 在整个应用程序中还有很多其他的require_once调用,它们的处理时间都不到1%。

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. 效果不佳的require_once包含的文件与其他任何文件都没有明显不同或更大,所以我不确定是什么原因导致了这个问题。 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. 我正在使用XAMPP对Windows进行分析。 Normally the application runs on a unix box. 通常,应用程序在unix框上运行。 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. 我没有一个简单的方法将xdebug放到盒子上,所以我尝试比较结果可能是不可行的。

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): 最后一个编辑:这是一个代码的概念,如果有帮助(故意模糊的标准CYA法律原因等等等等):

This class is the one with the slow include (test.inc): 这个类是缓慢包含的那个(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. 我有很多其他VO / DAO对象以完全相同的方式构建,没有任何问题。 All are located within the same respective paths. 所有都位于相同的路径内。

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. 单个require_once()的总程序时间的12%确实听起来非常过分。

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. require_once()保存一个已包含的文件的查找表,因此可能会减慢必须引用该查找表的速度。 If this is the cause, you could solve it by using require() rather than require_once() wherever possible. 如果这是原因,您可以尽可能使用require()而不是require_once()来解决它。

  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! 哦,顺便说一下 - 如果你的代码中最大的问题区域是require_once() ,那么听起来你的代码已经做得很好! I dream of the day require_once() even shows up in my profiler reports, let alone with an significant effect. 我梦想有一天, require_once()甚至出现在我的探查器报告中,更不用说具有显着效果了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM