php - 启用 Xdebug 后,PHP 运行速度异常缓慢

标签 php xdebug php-5.6

我已经在我的 PC(Windows 10)上安装了 Apache 2.4 和 PHP 5.6。

启用 Xdebug 后,PHP 的运行速度比没有 Xdebug 时慢 10 倍(!)。

这是php.ini配置:

zend_extension = "php_xdebug-2.3.3-5.6-vc11-x86_64.dll"
xdebug.remote_autostart = 0
xdebug.profiler_enable = 0
xdebug.profiler_output_dir = "C:\PHP\tmp"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_mode=req
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port=9000
xdebug.idekey=netbeans-xdebug
xdebug.trace_output_dir = "C:\PHP\tmp"
xdebug.auto_trace = 0
xdebug.var_display_max_depth = 3
xdebug.remote_connect_back = 0

我已确保禁用分析器和自动启动。 有谁知道这种行为的原因是什么?

最佳答案

来源:https://www.phase2technology.com/blog/profiling-production-whats-slowing-you-down

Instrumentation in interpreted languages, like PHP and Javascript, involves hooking into the runtime and explicitly collecting information about every function call as is occurs. This allows you to view the elapsed time spent, a call graph of function calls in the stack, memory and CPU stats, and other system data about your code as it executes on each request. Instrumented profiling does add overhead however, and it can be significant; this depends on the complexity of your application. This makes instrumented profiling ideal for development and debugging sessions, but limited for ongoing production analysis and monitoring.

检测的一个很好的替代方法是基于样本的分析。

Sample-based profiling involves taking snapshots of an application at fixed intervals. Each snapshot records the currently-executed function(s), and the aggregate of these snapshots is used to approximate when and where time is being spent in your code. This provides much less detail than instrumented profiling but without the significant added overhead, making it ideal for production use.

sample_prof有关使用 PHP 进行基于样本的分析的示例。

关于php - 启用 Xdebug 后,PHP 运行速度异常缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31882554/

相关文章:

php - 在 Docker 中安装 XDebug

php - Symfony 插入查询 : setting a non-null value with "false" sets it to "null"

php - SQL 数据库插入与选择

testing - PHPUnit、代码覆盖率、xdebug 和 html 报告

php - Laravel 5 Controller 将 JSON 整数作为字符串发送

.htaccess - 如何在 Ubuntu、nGinx 和 codeigniter 中启用 URL 重写?

PHP 严格标准 : Only variables should be passed by reference//array_pop

php - mySQl 连接随机用户值

javascript - 点击链接时的点击计数器 PHP/JS

使用 xdebug 进行 PhpStorm 远程调试