Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDEBUG to always run, not only on GET request

Tags:

php

xdebug

The title isn't my best; I was wondering how it's possible to run XDEBUG each time a script is executed on a local server, I have access to all configuration files you'd need, and I have XDEBUG for PHP running happily currently.

The only thing is it only runs when there's a GET request formed with the key of XDEBUG_PROFILE set to true, or just set, and currently with the framework I'm working on,

  1. The framework doesn't allow for extended GET requests in the URL, only slug-related data to be presented, and

  2. If I try and set $_GET['XDEBUG_PROFILE'] = true in a file on the framework, such as a Controller, the profiler gives unusual data, and creates profiles on other requests such as favicon loads and such and such, which gives awkward data to sift through.

So I thought it'd be a smart idea to be able to trigger XDEBUG on every script, just while I do development on the framework to get performance records, etc...

My current XDEBUG config in php.ini:

[XDebug]
;;;;;;;;;;;;;;;;;;

extension=php_xdebug.dll
xend_extension_ts="C:/xampp/apache/modules/php_xdebug-2.4.1-5.6-vc11.dll"

zend_extension = "\xampp\php\ext\php_xdebug.dll"
xdebug.collect_vars = 1
xdebug.show_local_vars = 1
xdebug.collect_params = 4
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "\xampp\tmp\"
xdebug.profiler_output_name = "cachegrind.out.%u.%R"
xdebug.profiler_enable_trigger = 1

xdebug.remote_host=127.0.0.1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp

I tried to search this up, but the only tutorials were how to actually set up XDEBUG itself, which I've already done, I thought the changed variable would be xdebug.profiler_enable_trigger = 1, but wasn't completely sure.

Thanks in advance!

like image 447
Jack Hales Avatar asked Jan 04 '17 14:01

Jack Hales


1 Answers

for Xdebug 2.x add this line to your php.ini:

xdebug.remote_autostart = 1

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.

https://xdebug.org/docs/remote

for Xdebug 3.x

xdebug.start_with_request = yes

On migrating from 2.x -> 3.x you will also have to change other settings, see here. For example remote_host was renamed to client_host.

like image 141
Fabian Horlacher Avatar answered Oct 04 '22 06:10

Fabian Horlacher