Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xdebug makes PHP way too slow

I know that Xdebug makes PHP slower, but on my Ubuntu 16 PC it makes PHP much slower only when listening to Xdebug is enabled in PhpStorm, in other cases speed is fine.

But now I'm trying to install development environment on MacOS with Docker.

So in few words: I've found a benchmark script. When I check PHP speed with Xdebug installed and enabled, it takes about 28-32 seconds to execute it. If I build a container without Xdebug installed and configured, script execution time is about 0.8-1.1 sec which is 30+ times faster!

Is there a chance that I configured something wrong and server sends 'Xdebug response' all the time?

Not sure actually how that works, but I am sure that it should not be like that.

I am using Docker, Ubuntu 16.04 container, PHP 7.2, Xdebug v2.9.1, Apache.

Here are my Xdebug settings:

zend_extension = "/usr/lib/php/20190902/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9003
xdebug.remote_host=host.docker.internal
xdebug.idekey=PHP_STORM
xdebug.remote_connect_back=off
xdebug.profiler_enable = 0
xdebug.remote_autostart = 0
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = req

Yet another thing. I am able to start debugging with this Xdebug listening icon, when all guides say that I should use 'Add Configuration' option and add Xdebug service.

Could you please tell me if I am doing something wrong?

Xdebug listening

like image 771
Дима Лизунов Avatar asked Feb 16 '20 20:02

Дима Лизунов


People also ask

Does xdebug slow PHP?

Yes, debuggers like XDebug reduce the performance of the PHP server.

What is xdebug Remote_host?

Xdebug is an extension for PHP to assist with debugging and development. It was determined that Xdebug is configured with xdebug. remote_connect_back option enabled as shown in the following example. xdebug.remote_enable= true xdebug.remote_connect_back= true xdebug.remote_host= 127.0.

How do I debug PHP locally?

You must configure your PHP Executable through the PHP Executables Preferences page before you can debug locally. To locally debug a PHP Script: Set breakpoints at the relevant places in the file that you would like to debug by double-clicking the vertical marker bar to the left of the editor. Save the file.

What is the best way to debug PHP?

This helps you to target your optimization efforts. The two main debuggers for PHP are Zend and Xdebug, which can both profile your code. I have xdebuginstalled, which is the free debugger, and I use the Eclipse IDE, which is the free IDE.

Is Xdebug slowing you Down?

Many of our developers use XDebug extensively during development and testing. A 2-5x slowdown while running a debug session is not unexpected. Little did I know that just having the extension installed brings along some significant slowdown.

How to see what is slow in a PHP application?

The excellent Xdebug extension has many useful features for assisting application developers, but today we’ll be looking at one specific feature that can help us see exactly what is slow in the application: profiling. Profiling a PHP application can explain how much time the server spent in each function, each file, and each code path.

How bad is a 2-5x slowdown while running a debug session?

A 2-5x slowdown while running a debug session is not unexpected. Little did I know that just having the extension installed brings along some significant slowdown. This is amplified in docker, where every System IO call brings with it a lot of overhead due to the virtualization in Docker for Mac.


2 Answers

I was facing the somewhat same issue, there was a problem with my configuration.

I was connecting to web server via a remote network address (like 192.168.xx.xx, 10.10.xx.xx) instead of local machine address (like 127.0.0.1 or localhost).

May be there was some routing issues within my docker configuration or some other settings. Though I did not got to the root cause but it solved my problem.

This worked out and my debugging become fast.

like image 77
Nahid Ali Avatar answered Oct 16 '22 00:10

Nahid Ali


I had the same issue until I found out, that the Xdebug extension in Chrome was causing this. If it is disabled the loading times are fine, if it is enabled a page reload often times took over 60s compared to 5s with Xdebug disabled. Did not make any difference if Xdebug in PHPStorm or Container was enabled or not.

like image 35
Cihan Avatar answered Oct 16 '22 00:10

Cihan