67

If I enable xdebug by settting xdebug.remote_enable=1, the apache server becomes very slow; once I change the setting to 0, it's normal.

I found a same question here: XDebug really slow, but the answer isn't helpful. I didn't enable profiling:

xdebug.profiler_enable=0
xdebug.auto_trace = 0
xdebug.trace_output_dir = /tmp/xdebug
xdebug.trace_output_name = trace.%c

I checked there's nothing under /tmp/xdebug folder.

When xdebug remote debug is enabled and I enable debug listening in PHPStorm, it takes a short while to stop at the breakpoint, but not as slow as disabling phpstorm debug listening.

My environment is: php + apache + xdebug on local centos VM, my mysql db and PHPStorm are on Windows desktop for development. MySQL is not slow.

Appreciate for help.

Community
  • 1
  • 1
Will-i-Am-Davidon
  • 1,532
  • 1
  • 14
  • 15
  • 1
    Yes! xdebug makes code executing slower (not extremely slow, but slower), even if you are doing no debugging -- simply because it keeps track of what is going on inside (function calls and their parameters; watching for possible exceptions etc). What is the rest xdebug options you have there? – LazyOne Jul 19 '13 at 08:44
  • 1
    This is not my case. I've been always using xdebug. My question is aobut remote debug enabled: when xdebug.remote_enable=1 but disabling debug listening in IDE (PHPStorm), it becomes very slow. It's not slow on any other cases. – Will-i-Am-Davidon Jul 21 '13 at 00:17
  • Once again: what are the rest of xdebug setting you have there? Because .. if you have configured xdebug to establish connection on **each** request .. and debugging client (PhpStorm in our case) is not responding (not listening) .. you will see 1-2 sec delay for each request (while xdebug is trying to establish connection). – LazyOne Jul 21 '13 at 10:36
  • The following are copied from phpinfo(). It's worth to mention that my case is not only 2 seconds delay, it's over 1 minute, too slow to be able to work. xdebug support enabled Version 2.1.4 Supported protocols Revision DBGp - Common DeBuGger Protocol $Revision: 1.145 $ Directive Local Value Master Value xdebug.auto_trace Off Off xdebug.collect_assignments Off Off xdebug.collect_includes On On xdebug.collect_params 4 4 xdebug.collect_return Off Off xdebug.collect_vars Off Off xdebug.default_enable On On xdebug.dump.COOKIE no value no value – Will-i-Am-Davidon Jul 22 '13 at 01:14
  • xdebug.dump.ENV no value no value xdebug.dump.FILES no value no value xdebug.dump.GET no value no value xdebug.dump.POST no value no value xdebug.dump.REQUEST no value no value xdebug.dump.SERVER no value no value xdebug.dump.SESSION no value no value xdebug.dump_globals On On xdebug.dump_once On On xdebug.dump_undefined Off Off xdebug.extended_info On On xdebug.file_link_format no value no value xdebug.idekey root PHPSTORM – Will-i-Am-Davidon Jul 22 '13 at 01:18
  • xdebug.max_nesting_level 100 100 xdebug.overload_var_dump Off Off xdebug.profiler_aggregate Off Off xdebug.profiler_append Off Off xdebug.profiler_enable Off Off xdebug.profiler_enable_trigger Off Off xdebug.profiler_output_dir /tmp /tmp xdebug.profiler_output_name cachegrind.out.%p cachegrind.out.%p xdebug.remote_autostart Off Off xdebug.remote_connect_back Off Off – Will-i-Am-Davidon Jul 22 '13 at 01:19
  • xdebug.remote_cookie_expire_time 3600 3600 xdebug.remote_enable Off Off xdebug.remote_handler dbgp dbgp xdebug.remote_host 10.25.99.38 10.25.99.38 xdebug.remote_log no value no value xdebug.remote_mode req req xdebug.remote_port 9000 9000 xdebug.scream Off Off xdebug.show_exception_trace Off Off xdebug.show_local_vars Off Off xdebug.show_mem_delta Off Off xdebug.trace_format 0 0 xdebug.trace_options 0 0 xdebug.trace_output_dir /tmp/xdebug /tmp/xdebug xdebug.trace_output_name trace.%c trace.%c xdebug.var_display_max_children 128 128 – Will-i-Am-Davidon Jul 22 '13 at 01:19
  • xdebug.var_display_max_data 512 512 xdebug.var_display_max_depth 3 3 – Will-i-Am-Davidon Jul 22 '13 at 01:20
  • Unable to make the comments look better, sorry – Will-i-Am-Davidon Jul 22 '13 at 01:25
  • Over 1 minutes? No idea what may cause such HUGE delay. I've checked xdebug settings and found nothing that I could called "suspicious/wrong". I have no clue about such behaviour, sorry. – LazyOne Jul 22 '13 at 08:44
  • I wonder this is the "normal" behaviour, because when remote debug is enabled, xdebug expects to get response from remote port 9000, while IDE (phpstorm) disabled debug listening, so xdebug can't get any response and just silly wait for long time. But it's inconvenient if it's so silly. zend debug doesn't behave as this, I remember. – Will-i-Am-Davidon Jul 23 '13 at 01:58
  • **Normal** behaviour for xdebug is to wait for about 1 second (less than 2 seconds MAX) when attempting to connect to debugging client. 1 Minute is way too much -- I suggest checking/refreshing your environment (whatever you may have there). Once again -- normally xdebug should not be attempting to connect to a client unless it sees xdebug cookie/get param .. or configured to connect on **every** request. In all other instances it should proceed without connection attempt. It's extremely unlikely (99.999% IMO) that PhpStorm has anything to do with it. – LazyOne Jul 23 '13 at 08:54

16 Answers16

85

In my case this was caused by having

xdebug.remote_autostart = 1

set in php.ini. That causes xdebug to try to connect to remote debugger on every request. I had some PHP handled styles, auto_preppend_file and other PHP files in the request and for each of them it waited approximately 2secs, which added up to sth. like 15 seconds or so. Setting

xdebug.remote_autostart = 0

solved the problem completely. xdebug connects only when debug cookie is present. Please note you need to remove the debug cookie/param if you are not in debug session for this fix to work.

Here is my config that I use to setup xdebug.

Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82
  • 1
    Simply brilliant, in my case I use `sublime text` and I modified the file: `etc/php5/conf.d/xdebub.ini` (with the same results). thank you very much! – gmo Jan 07 '14 at 15:31
  • 1
    Thank you! When I wasn't listening for the PHP Debug Connections, my site would get a timeout. With your changes it works again :) – Krenor Sep 11 '15 at 08:17
  • 2
    Thanks @Tomáš Fejfar I set disable two thing please suggest me is it right ? xdebug.remote_autostart = 0 xdebug.profiler_enable = 0 – Manish Goswami Nov 06 '17 at 05:00
  • 1
    This is a config I've been using: https://gist.github.com/tomasfejfar/4e8e27ece29b142a7ec7f54f4fa44872 – Tomáš Fejfar Nov 08 '17 at 09:57
  • 1
    Any suggestions for case without *debug cookie*? – Tarasovych Jan 23 '19 at 20:42
  • What do you mean? Like with https://xdebug.org/docs/all_settings#remote_connect_back? – Tomáš Fejfar Jan 25 '19 at 08:41
  • 1
    Can you please elaborate about the cookie/param thing? What is this and where can i find it. – i.brod May 01 '19 at 20:59
31

Experienced also low performance with XDebug (loading Captcha in 6 seconds instead of milliseconds) Remarks on this page got me on the way to identify the cause.

Turned off the profiler and loading time was divided by 3. Still slow, but better already.

xdebug.profiler_enable = 0
Coloured Panda
  • 3,293
  • 3
  • 20
  • 30
user2992220
  • 1,092
  • 1
  • 12
  • 20
  • I had a bunch of files (14GB!) in the tmp directory in my MAMP install which were still slowing it down even after I disabled profiler. I deleted them and it seems to be working better! – Sabrina Leggett Aug 20 '15 at 17:10
  • For me this setting reduced loading time substantially. Thanks – Ole_S Sep 16 '16 at 15:50
  • 1
    You could still have `xdebug.profiler_enable = false` `xdebug.profiler_enable_trigger = true` It will only enable profiling when the cookie says so – unloco Nov 15 '16 at 22:54
29

Just as further reference... in case anyone has the same/similar problem ... (60 sec. timeout)

First double check xdebug.remote_autostart is disabled to avoid the auto connection.
As @LazyOne pointed out, and @Tomáš Fejfar explains as well.

xdebug.remote_autostart
Type: boolean, Default value: 0
Normally you need to use a specific HTTP GET/POST variable to start remote debugging (see Remote Debugging). When this setting is set to 1, Xdebug will always attempt to start a remote debugging session and try to connect to a client, even if the GET/POST/COOKIE variable was not present.

With this, I recover my normal speed when the debug cookie wasn't present...
But!... I still get very slow response (60 sec. timeout) from the server when the cookie was manually activated.

So, after reading the Xdebug Documentation and checking my config,
I find out that I had enable xdebug.remote_connect_back

xdebug.remote_connect_back
Type: boolean, Default value: 0, Introduced in Xdebug > 2.1
If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER['REMOTE_ADDR'] variable to find out which IP address to use. Please note that there is no filter available, and anybody who can connect to the webserver will then be able to start a debugging session, even if their address does not match xdebug.remote_host.

So all calls to the server was trying to be debugged, making the server very slow and also insecure.

Disable this option and and verified that I had well-defined xdebug.remote_host pointing to my machine, I got an acceptable response ~1sec. and only when the cookie is enabled.

So in brief, my configuration file end up like this:

zend_extension             = "/absolute/path/to/your/xdebug-extension.so"
xdebug.remote_enable       = 1
xdebug.remote_autostart    = 0
xdebug.remote_connect_back = 0
xdebug.remote_host         = "192.168.1.2"
xdebug.remote_port         = 9000
xdebug.remote_handler      = "dbgp"
xdebug.remote_mode         = req
xdebug.remote_log          = "/tmp/xdebug.log"

Note: I made this changes in etc/php5/conf.d/xdebug.ini file and not in php.ini

Edit:
As @Riimu & @jdunk point it out thanks to both, you may want to set also:
* see comments for details

xdebug.remote_cookie_expire_time = 0
// or
xdebug.remote_cookie_expire_time = -9999
Community
  • 1
  • 1
gmo
  • 8,860
  • 3
  • 40
  • 51
  • 2
    I would also like to point out, that you may also want to set `xdebug.remote_cookie_expire_time` to 0, if you are using GET values to activate the debugger. Otherwise xdebug will automatically set the debugging cookie, which will trigger the remote debugger on later calls. – Riimu Mar 08 '15 at 11:39
  • @Riimu you're a lifesaver. I couldn't find this anywhere else on the internet! Except here (though not useful) http://xdebug.org/archives/xdebug-general/0783.html – jdunk Dec 30 '15 at 21:51
  • 1
    It's also possible (and probably a good idea) to set `xdebug.remote_cookie_expire_time` to a negative value, like `-9999`. That way the cookie doesn't actually get stored (because it's "not expired yet") if the client's clock is slower than the server's by a second or more. – jdunk Dec 30 '15 at 21:54
7

Also, if you do want to leave xdebug.remote_autostart = 1 enabled all the time, in your Phpstorm settings try increasing the max simultaneous sections. This should reduce hanging and blocks, but will still result in a performance impact based on my experience.

enter image description here

MacNeil
  • 81
  • 1
  • 2
6

In my case low performance was caused by having 200+ breakpoints set in PHPStorm which were evaluated on every request by xdebug.

Clearing those breakpoints in PHPStorm increased perfomance from 60 sec to 6 sec per request.

Jovan D.
  • 91
  • 1
  • 3
3

I am using PHPStorm 7.1 and the Apache server installed by Xampp 1.8.2, all that under Windows 8.1. I did experience slow interoperability between Chrome and PHPStorm in debug mode when having breakpoints set.

Speed was notably improved by installing the last version of the XDebug dll (use the XDebug wizard to determine which version to download), copy the dll in your php/ext dir and change the php.ini so the new XDebug dll will be loaded. Stopstart Apache and see the difference.

I could verify that a similar performance gain occured when debugging a webapp with Eclipse (Juno with PDT) using the internal Eclipse web browser.

Jean-Pierre Schnyder
  • 1,572
  • 1
  • 15
  • 24
2

Sometimes if you have other services working in the port 9000, Xdebug will not be able to connect to his server at the port 9000 and it will make it slow because it will get timeout on every request.

Try to change the default port(9000) where xDebug is listening, I used 9090 for the example but you can use whatever free port you have:

xdebug.remote_port=9090

Then remember to change the port where xDebug is listening on you IDE, I'm using Visual Studio Code:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9090,
            "log": true
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9090
        }
    ]
}
Santi Barbat
  • 2,097
  • 2
  • 21
  • 26
2

For me, Xdebug version 2.7.2 was slow on including vendor's autoload.php Xdebug ersion 2.6.0 was just fine.

Paul Bönisch
  • 294
  • 2
  • 10
  • 2
    Unluckily it seems not possible if you are running PHP 7.3+ as XDebug 2.6.2 stops at PHP 7.2 – Benj Jun 29 '19 at 00:04
2

I had the same problem with a docker container and Visual Studio Code , used this

; disables xdebug traces in error messages
xdebug.default_enable = "Off"

Thanks @tomáš-fejfar

maccevedor
  • 155
  • 2
  • 5
1

It's likely that there are some networking timeouts that happen here. The best way to find out what's going wrong is to try to debug a command line script. If that still has the same issue, then use strace to see what it is hanging on:

export XDEBUG_CONFIG="idekey=yourname"
strace -tt -o /tmp/strace.log php full/path/to/script.php

Then have a look at /tmp/strace.log and see where the slow down happens.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • When phpstorm stops debug listenting while xdebug remote debug is enabled, the command provided by @Derick will also be blocked. So I think this is how xdebug works: You have enabled xdebug remote debug in apache, and have enabled xdebug from web browser or command line (it looks {{{export XDEBUG_CONFIG="idekey=yourname"}}} command enables command line xdebug), but IDE (PHPSTORM) stops listening, so xdebug can't get any response from IDE, and is so halted. – Will-i-Am-Davidon Jul 24 '13 at 00:43
  • 1
    No, when the IDE isn't listening, then the connect will timeout - not block. – Derick Jul 24 '13 at 08:31
  • Yes, you are right, it's timeout, but for me it looks blocked. From my observation and google search, this timeout is one minute. But I haven't found where to change this timeout period, I changed Timeout in httpd.conf, and default_socket_timeout in php.ini, there's no use, the xdebug timeout is still 60 seconds – Will-i-Am-Davidon Jul 26 '13 at 00:15
1

Just an headsup for people living in year 2022.

At least on XAMPP with PHP 8.0 & xDebug "xdebug.remote_autostart=1" parameter has been renamed to "xdebug.start_with_request=yes". Commenting this row gave 3x faster rendering speed when browsers xDebug-plugin is disabled. After enabling it's slow as usual, but that's to be expected.

For an example, my Laravel project loads really complex controller-route with dozens of Eloquent queries in 600ms when xDebug is completely disabled on php.ini . When it's activated with "start_with_request" set to false it renders in 1.6 seconds. When debugging is enabled either from plugin or "start_with_request" is set true it takes about 4.5 seconds.

Janne
  • 1,111
  • 3
  • 12
  • 17
  • 1
    I had same issue. I had set start_with_request=yes for tracing but didn't set it back to "no". Performance was awful until I disabled it. – Gregory Bologna Aug 03 '22 at 20:30
0

For me I had

xdebug.remote_connect_back = 1

which slowed everything and stopped remote debugging from working. Once I remove it, everything works fine.

Tashi
  • 477
  • 4
  • 12
0

In case anyone still struggle with slow xdebug on Windows platform, reducing number of breakpoints worked for me. From whatever reason, each breakpoint slows down debugging ...

salih0vicX
  • 1,363
  • 1
  • 8
  • 9
0

For me helped in Xdebug 3 to disable "develop" in xdebug.mode in php.ini.

xdebug.mode=debug,develop

changed to

xdebug.mode=debug
Petr Pánek
  • 369
  • 3
  • 6
0

I have the same problem on an Windows 10 machine with VS-Code (Visual Studio Code) IDE and XAMPP for local Wordpress development: PHP takes 10 to 20 times longer for execution when xdebug is activated.

There is a workaround for this problem. In php.ini configure:

xdebug.start_with_request = trigger

and in your PHP-Code use:

xdebug_break();

As a consequence of this, xdebug will start working only if it receives the signal "xdebug_break();" from your PHP code. There will be a breakpoint in the line after that. Then you can continue with step debugging etc.

In VS Code I'm using the PHP extension pack and then start the VS Code debugger with "Listen for xdebug".

Jörg
  • 99
  • 2
  • 10
0

For me the problem was that xDebug slowed down my PHP requests only when the debugger was not started, because VS Code was apparently waiting for it.

Setting the timeout to zero (xdebug.connect_timeout_ms = 0) fixed the lag for me and still allows me to start the debugger and stop at breakpoints.

This is my full xDebug config in php.ini:

zend_extension = xdebug
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.connect_timeout_ms = 0
dag0310
  • 13
  • 4