1

I'm using vim with the Vdebug plugin and Xdebug to debug the WebDAV server of a nextcloud instance. Nextcloud uses SabreDAV, so the WebDAV server is a PHP script. The desktop file synchronization client (owncloud) which nextcloud uses keeps a local folder in sync with the nextcloud web storage.

I want to debug issues with quota calculation of the nextcloud server upon a WebDAV file upload (presumably PUT) request. However, the owncloud client issues multiple WebDAV requests to the server if a local file changes, where the first request(s) is/are not of importance to me (presumably a PROPFIND or similar). Only after this uninteresting request(s), an upload request is sent. However, if I set up vim to listen for an incoming connection by Xdebug (:VdebugStart), the first uninteresting WebDAV request establishes the connection, but I would like to establish the connection for later incoming Xdebug connections. However, I am not fast enough to set vim into listen mode before the owncloud client calls the server again with the interesting WebDAV request.

There might be two ways of dealing with this:

  • Make vim listen for a new Xdebug connection very fast after the first (uninteresting) one ends
  • Make PHP not establish an Xdebug connection right from the start, but only when a certain code block, which corresponds to the interesting upload request by the client, is called. I could insert some PHP function xdebug_connect_now_to_client() function instead of Xdebug connecting to vim right from the start.

Do you know a possiblity to archieve one of those goals, or is there another solution?


Relevant php.ini entries:

zend_extension=xdebug.so
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
; have to set this, because owncloud does not set the
; XDEBUG_START_SESSION=true GET parameter
xdebug.remote_autostart=on
xdebug.idekey=netbeans-xdebug
akraf
  • 2,965
  • 20
  • 44
  • You can use `xdebug_break();` in PHP code to trigger a breakpoint. This should also work if debug session was not established yet (which should usually happen when xdebug executes entry point script). For this you most likely need to `xdebug.remote_autostart=off` so xdebug will not attempt to debug every single request. – LazyOne Oct 06 '17 at 08:39
  • At the same time my thoughts are: even if you have "automatic debug" (`xdebug.remote_autostart=on`) ... if no breakpoint is triggered then execution should be continued normally, which then end xdebug session so it's ready for next one. This means -- if breakpoint was set in some code that only gets executed under certain conditions .. then you should have few "unwanted" sessions that just execute normally (as there will be no breakpoints in interesting code) and only one that hits the code will be dealt with. at very least that's how I see it (PhpStorm user here, no idea how vim works here) – LazyOne Oct 06 '17 at 08:46

1 Answers1

1

Like you I ran into this issue debugging WebDav requests in NextCloud using xdebug and vdebug.

I like LazyOne's suggestion above to code in a break point.

What I ended up doing was to set

xdebug.remote_autostart=0 

and to as much as possible use the addon below to enable debugging only for my request.

https://addons.mozilla.org/en-US/firefox/addon/xdebug-helper-for-firefox/

I also found it helpful to enable tracing initially to get at least some idea where in the code I needed to look, which might also help you put in a manual breakpoint. Here again you can use the addon to minimize requests that will generate a trace.

xdebug.remote_log=/tmp/xdebug_remote.log
xdebug.trace_options=1
# Write a trace file per process
xdebug.trace_output_name=trace.%p
# Only trace if we get XDEBUG_TRACE
xdebug.auto_trace=0
xdebug.trace_enable_trigger=1

I'm using php-fpm I also set

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
pm = static

so that there's not a ton of processes creating trace files and issuing requests