Disable XDebug at runtime - php

I'm trying to run my Symfony website with XDebug, and PHP sockets at the same time.
To run the website:
bin/console server:start
To run the sockets
bin/console sockets:start
My sockets will not start unless XDebug is disabled.
However, I would like XDebug to be enabled for my website.
A solution is to disable XDebug system-wide in php.ini, but I would like to know if it is possible to do so at runtime, so I could unload XDebug before starting sockets when I run sockets:start.
Thank you!

To fix, before PHP 7 people would suggest to comment out the extension from php.ini file. However, in PHP 7 they are no longer in there.
Instead, we use the phpdismod command.
$ sudo phpdismod -s cli xdebug
The -s flag tells it to disable Xdebug for the CLI SAPI (/etc/php/7.0/cli) and not FPM.
And just like that, the warning message should be gone. No need to restart PHP

just assign two different ports for the debugger in the xdebug.ini (the CLI has it's own) -
because it sounds alike, as if it would get stuck due not being able to bind the port.
... this additional port then needs to be set up in the IDE, too.

Related

Disable blackfire module temporary

I've sucessfully installed the blackfire agent, cli tool and probe and it works fine. I've disabled the xdebug module while profiling with bf.
Now I want to use xdebug as I did before, but xdebug does not work, it just won't enter a debugging session. No breakpoint and not even xdebug_break work. A quote from the producers website says:
Known incompatibilities
Please note that PHP compiled with debug are not supported and that
the Probe may conflict with XDebug or XHProf; disable those extensions
when enabling the Probe.
Is there a way to disable the blackfire agent WITHOUT uninstalling the whole blackfire tool chain ? Moving the file /etc/php5/conf.d/90-blackfire.ini to a backup location didn't work.
Update
What works is uninstalling the php agent sudo apt-get remove blackfire-php. But I'm pretty sure there must be a better solution.
You can simply edit the file /etc/php5/conf.d/90-blackfire.ini and comment the following line extension=blackfire.so. Don't forget to restart apache2 or php-fpm
You can run the next command to turn off PHP extensions/modules:
$ sudo phpdismod blackfire
The opposite of this command is:
$ sudo phpenmod blackfire
To apply all changes you must restart your service. Example:
$ sudo service php7.4-fpm restart

PHP composer xdebug warning

New to PHP. Working on a PHP project and have xdebug enabled to be able to debug my php applications. The production server does not have xdebug enabled because it is handled by another team. On my local machine, when I run composer it gives me a warning saying
You are running composer with xdebug enabled. This has a major impact on
runtime performance.
I do not want to disable xdebug when I am developing. Just wanted to confirm that running xdebug in dev environment should have no impact on the composer installing libraries/performance of the app on the production server.
I do not want to disable xdebug when I am developing. Just wanted to confirm that running xdebug in dev environment should have no impact on the composer installing libraries/performance of the app on the production server.
There is a huge impact of just loading Xdebug. It slows the Composer run down by 3x or 4x, even when the profiling feature is not enabled.
In other words: xdebug is invaluable for debugging, but increases the memory used and processing time of Composer.
How to disable Xdebug for Composer runs?
My suggestion is to write a little invocation helper for running Composer.
The helper is a bash or batch script calling PHP with a custom php.ini, especially configured for Composer. Lets call it: php.ini-composer.
You could copy your current php.ini and adjust it for the Composer run, by removing xdebug or commenting it out, like so: ;zend_extension = "/path/to/my/xdebug.so".
While you are at it: setting memory_limit=-1 is helpful, too.
The full command looks like so on Windows: php.exe -c php.ini-composer composer.phar %*
Just clone the idea for a bash script.
And you may find the full answer to your question in the Composer FAQ.
https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
It was added/updated just a few hours ago.
Some alternatives (instead of using seperate ini file) are also mentioned here.
Modern versions of Composer can work around having XDebug enabled by default for the CLI SAPI. It spawns a new PHP process with the XDebug extension disabled in case it is detected.
You can disable this behaviour by setting the following environment variable:
COMPOSER_ALLOW_XDEBUG=1
Found this in the documentation: https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
Like with web scripts, expect CLI scripts to run slower as well.
If you need the added runtime performance, you can disable XDebug on CLI only. Set your PHP installation so that it uses different ini files for CLI and your server, as this answer suggests.
To fix this, prior to PHP 7 people would suggest to comment out the extension from your php.ini file.
However, in PHP 7 they are no longer in there.
Instead, we use the phpdismod command.
sudo phpdismod -s cli xdebug
The -s flag tells it to disable Xdebug for the CLI SAPI (/etc/php/7.0/cli) and not FPM.
And just like that, the warning message should be gone. No need to restart PHP.
In addition to this, there is a plugin that downloads packages in parallel to speed up the installation process.
Create a file named php-composer.ini somewhere with the following content (the minimum php config for composer):
extension_dir = "D:/php/ext/" ;according to your system
extension=php_openssl.dll
memory_limit=-1 ;optional
Now create a file named cmz.bat with the following contents. (edit paths accordingly)
#ECHO OFF
php -c "D:\php-composer.ini" "C:\ProgramData\ComposerSetup\bin\composer.phar" %*
add this file to your system path or your project root.
Now use cmz instead of composer and you will not see that message and hopefully the composer speed would be increased.
note: Some package need specific php extensions. you need to add them to php-compsoer.ini file or appending --ignore-platform-reqs switch to cmz.bat file
On a fresh download of Symfony 3.1 and PHP 7.0, you can run the following (having edited it to include the path to your composer.phar file):
php -n -d extension=json.so -d extension=phar.so -d extension=pdo.so -d extension=ctype.so /path/to/composer update
If you have any extra vendors to your composer.json file, you might find that they have a dependency on an extension, so you need to include that by adding -d extension=name_of_extension.so to the list.
What's happening here is the -n flag goes with PHP defaults - it doesn't load any ini PHP config files, so XDebug is never loaded. Then each of the -d flags allows you to dynamically set config values, so you can include extensions.

Is it possible to use Xdebug with the built in PHP test server?

Basically my question says it all.
I'd like to be able to inspect the state of the variables of my script, set breakpoints etcétera, without the need to install Nginx, apache or PHP-FPM?
Is this doable, if not what would be my options?
Ok so parting from this article I've managed to use xdebug.
I installed PHP 5.5 on Mac OS X 10.10 using homebrew
Install PHP if it has not been installed, make sure to install it with the xdebug extension;
in my case I used$ brew install php55-xdebug or if you have pecl and php already installed use $ pecl install xdebug.
You can check if the extension is installed by executing $ php -m | grep xdebug.
If you use VIM as your "IDE", I'd recommend to install the vim pathogen plugin, then install the xdebugger vim plugin; which I've modified to be pathogen compatible.
$ cd ~/.vim/bundle && git clone https://github.com/Triztian/xdebugger.git
Next we have to enable the xdebugger extension; to do so first you need to find out which php.ini file is being loaded, you can check that by running $ php -i | grep "File => /". After you've found the correct init file you must add the follwing lines at the end:
xdebug.remote_enable=On
xdebug.remote_autostart=On
If using PHP's built-in development server, you can use the -c argument to specify a php.ini file.
Now, start the php development server (in my case $ php -S localhost:8080 -c /usr/local/etc/php/5.5/php.ini) and open VIM. After VIM is open press <f5> so that the xdebugger starts listening for a connection; on your browser navigate to localhost:8080/index.php (or any php script) so that it triggers the xdebugger connection if everything has been setup correctly.
You should no be in a debugging session, look at the plugin's readme to see how it works.
You can use php built in web server. It was mean't to be used for development.

How to use Xdebug on the terminal?

I am trying to find a way to debug PHP other than var_dump() and I noticed Xdebug. I cannot find on the internet if Xdebug has a command-line version (I dont want to use a GUI version, bear with me(sshing another linux system)). If there is, how can I use it? If no, is there any other PHP debugging tools that can be run as command-line?
xdebug
Profiler:
With xdebug, you might run the profiler from CLI with this command:
php -d xdebug.profiler_enable=1 script.php
In order, to run this on the console, the box you are ssh'ing into must have PHP and Xdebug installed and configured.
Remote Xdebug:
Another option would be to use xdebug.remote_host with SSH tunneling/forwarding.
Forwarding is described here: http://derickrethans.nl/debugging-with-xdebug-and-firewalls.html
Remote Xdebugging here: http://xdebug.org/docs/remote
This allows to work with Netbeans or PHPStorm on the remote machine.
Xdebug's DebugClient
You might also use the simple DebugClient xdebug ships for CLI usage.
Every other debugging client, which supports the dbg-protocol, should work, too. http://xdebug.org/docs/install#debugclient
phpdbg
If you run PHP 5.6, then you might use phpdbg, which is the integrated debugger and perfect for CLI usage.

how can i associate/use PDT with eclipse in ubuntu?terr

I want to use PDT to debug PHP with eclipse. I am using ubuntu 9.04.
Can any one help me? please give details if possible.
Considering this thread and this one:
You have to ensure that xdebug is definitely loaded on the version of php you are using.
To do this, use the launch configuration you are using to try to run your script in debug mode and change it to run a script with phpinfo.php in it.
Also a Debug log would be good.
Add:
xdebug.remote_autostart=On
xdebug.remote_log="c:\temp\xdebug.log"
to your php.ini.
Then you have to insure that PDT is expecting Xdebug information on port 9000,
and have insured that your local Default PHP Web Server is http://127.0.0.1.
With the log, you might discover, for instance, that your php.ini files is not properly formatted, which could be enough to prevent you debugging PHP from PDT.
UYu would have to install PHP5 xdebug extension first,
sudo aptitude install php5-xdebug
after you would have to check your settings by editing /etc/php5/conf.d/xdebug
after you have to setup your php project to use xdebug and you should be done.
I'm use PDT in Ubuntu 9.04 and can fine debug my php projects.
first as already answered install php5-xdebug through apt-get or synaptic (I'm think you already install php5 itself in same way :) ). Then you must define php executables in Window/Preferenses/PHP/PHP Executables. You can point to /usr/bin/php, or can use 'Search...' button, but you must point initial search dir to nearest to your php exec binary. After found executable it always set to use Zend Debug by default. Edit executable to change 'PHP debugger' type to XDebug. And now a main trick. When you try debug your php scripts without create run configuration - it will always use Zend Debugger. You must create your own run configuration with XDebug setted as PHP Debugger. It's worked for me.

Categories