有没有办法测量 PHP 的解析时间?
通过运行时基准测试优化 PHP 代码非常简单。 通过代码块周围的 microtime() 跟踪 $start 和 $end 时间 - 我不是在寻找涉及 microtime() 使用的答案。
我想做的是测量 PHP 准备运行其代码所需的时间 - 代码解析/操作代码树构建时间。 我的理由是,虽然很容易就包含()网站上每个页面可能需要的每个类,但 CPU 开销不可能是“免费”的。 我想知道解析时间到底有多“昂贵”。
我假设 APC 等操作码缓存不属于该场景。
PHP 中解析时间的测量必须在 mod_php 中进行,我这样说是正确的吗?
编辑:如果可能,考虑代码中的 $_SERVER['DOCUMENT_ROOT']
用法会很有帮助。 命令解决方案可能需要一些修改才能做到这一点(但仍然是有价值的答案)。
Optimization of PHP code via runtime benchmarking is straight forward. Keep track of $start and $end times via microtime() around a code block - I am not looking for an answer that involves microtime() usage.
What I would like to do is measure the time it takes PHP to get prepared to run it's code - code-parse/op-code-tree-building time. My reasoning is that while it's easy to just include() every class that you might need for every page that you have on a site, the CPU overhead can't be "free". I'd like to know how "expensive" parse time really is.
I am assuming that an opcode cache such as APC is not part of the scenario.
Would I be correct that measurement of parse time in PHP is something that would have to take place in mod_php?
EDIT: If possible, taking into account $_SERVER['DOCUMENT_ROOT']
usage in code would be helpful. Command solutions might take a bit of tinkering to do this (but still be valuable answers).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。 有。
或者
然后将运行空脚本的时间
与运行(或失败)常规脚本所需的时间与我上面提到的添加内容进行比较:
我在大文件上使用了这种方法,并且 Core2Duo 2.4Ghz 上的 PHP5.3 可以解析每秒 1.5 和 4.5MB 的 PHP 代码(当然这很大程度上取决于代码的复杂性)。
Yes. There is.
or
and then compare time of running empty script
with time it takes to run (or fail) regular script with the additions I've mentioned above:
I've used this method on large files and PHP5.3 on Core2Duo 2.4Ghz can parse between 1.5 and 4.5MB of PHP code per second (it depends very much on complexity of the code of course).
一种方法是从命令行计时脚本的执行。
以 Linux 为例:
这有帮助吗? 也许它有助于发现不同脚本之间的相对时间,但它可能无法表明通过 Apache 模块所花费的时间
One method could be timing the execution of the script from the command line.
In Linux for example:
Does that help at all? Perhaps it is helpful for discovering relative times between different scripts, but it may not be indicative of time taken through the Apache module
对于您正在寻求的详细分析级别,似乎需要实现 Xdebug (http://xdebug.org/ )将为您提供最丰富的信息,而无需将代码切成分段。
For the detailed level of analysis you're seeking, it seems that implementing Xdebug (http://xdebug.org/) would give you the greatest information w/o having to chop your code into segmented pieces.