Is there a interactive debugger for php like ruby's debugger? - php

I watched the Creating a weblog in 15 minutes with Rails 2 and after 9 minutes in the video he shows ruby's interactive debugger, which allows you to call functions/methods from within a running script.
This goes way beyond breakpoints and looks very useful.
Is there something for PHP that gives similar functionality?

Install xdebug and then use one of the debug clients mentioned here.

Although Milen's answer is the only correct one circa 2009, and Xdebug is still a useful tool, using it requires you to recompile your PHP or to edit your php.ini runtime configuration to load it as a shared object. It also means using a specific client application that supports its network protocol, such as an IDE like PhpStorm.
An alternative is phpdbg, which is an interactive debugger that ships with PHP core versions 5.6 and later and can debug PHP scripts written to conform to PHP 5.4 or later.
Using it is simple:
phpdbg php_script_i_want_to_debug.php
Once in the debugger, type help to access the help menu.
If you don't already have phpdbg on your system, it may be because your PHP was configured without the --enable-phpdbg option. You can either:
Recompile your PHP, being sure to add --enable-phpdbg when you run ./configure (this will simply also build the phpdbg binary), or
download the phpdbg source independently and compile it against your installed PHP (assuming you have the PHP source available). Instructions for doing that, while sparse, are here.

Related

configuring php files in vscode

I run php files in Apache server. Also, i've added in user settings the code as
"php.validate.executablePath": "C:\wamp64\bin\php\php7.0.10\php.exe",
Still, i cant run php files? Help;
You have to install php debug extension in visual studio code
Try this
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
or you can try below one using php xdebug extension(this works for me)
http://www.accella.net/knowledgebase/debugging-php-with-visual-studio-code/
As the name suggests, php.validate.* directives are used to configure linting (i.e. parsing PHP source code to detect syntax errors):
Linting
VS Code uses the official PHP linter (php -l) for PHP language diagnostics. This allows VS Code to stay current with PHP linter improvements.
To run PHP scripts from within the editor you have a number of choices or none at all depending on what you want to do exactly. You can run command-line scripts from the integrated terminal, with an extension like Runner or Code Runner. As far as I know there's no way builtin way to lauch a browser in the preview pane that reloads as you save if that's what you mean. And you can certainly configure a debugger.

VSCode - php not installed?

I have VSCode installed, but don't seem to have php - i.e. there is no "php.exe" anywhere on my computer. No guides that I can find on the web about setting VSCode up for PHP suggests that I need to download and install php itself seperately (only debuggers and linters)... my question is:
Do I need to install PHP seperately? Should I have had to do this, or is there a bug in my VSCode installation...
Yes you need to install PHP from the php website and then tell VSCode where PHP.exe is located.
VSCode is an editor not an interpreter.
I think if you install PHP at the default location VSCode will automaticly pick it up but if not you need to specify its path in options.
If you install XAMPP you will get apache,php and mySql in one installation.
EDIT: an interpreter is software that translated your code(in your case PHP) into code that the CPU can understand and then executes.
#kpollock it' not you. Yes, it should seem obvious that the language should be installed manually or separately, so you should have gotten that part, sorry. But no, there doesn't seem to be information anywhere about defining the underpinnings. This "understanding" seems to be left to the individual through research as you're doing.
After I installed PHP I manually set my environment PATH to include the PHP folder. OR in VS Code you can go to menu>File>Preferences>User Settings, the settings are maintained as a JSON object (unlike VS) and there is a PHP section for the .exe path.
Since you mentioned Node, you may not have installed Node.js manually. (I don't know if Node comes with VS Code either.) It might have come in with a VS2015 extension like Gulp or some other higher-level functionality, or maybe it was an installation option with VSC. If you can't use node or npm from a console, set your environment PATH to include it.

Solution to debug PHP code on remote server, using remote IDE

There is an IIS server with the XDEBUG extension installed, running a PHP application. I can't change nothing on this server. Sometimes, the dev team here needs to debug it, without changing code. Just put some breakpoints and execute it step by step.
I can do it from my computer using Eclipse and remote debugging. But I would like to create a Debian server, in a VM, to make it easy for anyone with just a browser to place breakpoints and step debug that server, without needing to set up an environment.
I tried many Web-Based IDEs (codiad, cloud9, etc), but they don't offer XDEBUG integration. Is there any web-based IDE that I can install in my own server that offers PHP debugging? Please read this paragraph again and don't answer with spam
Or, is there anyway I could run something in the server side such as Sublime Editor, Notepad ++, or whatever, and see it running in a browser? Maybe a Java applet.
Any bright ideas will be very much appreciated! Thanks!
We just released support for debugging PHP with Xdebug inside Cloud9 IDE.
You can place breakpoints (normal or conditional), step over/in/out, set watch expressions, view the call stack, and inspect variables and values. There's also an REPL mode to evaluate code directly.
It's ready to try, but please make sure the correct dependencies are installed on the workspace by running the following commands:
$ npm install -g debug
$ sudo apt-get install php5-xdebug
Set your breakpoints, then click Run > Run With > PHP (cli) to start the debugger and PHP CLI script.
Would love to hear what your feedback is. Our goal is to add support for debugging PHP web pages and Python soon. The implementation is available open-source on GitHub (https://github.com/c9/c9.ide.run.debug.xdebug)
I also made a quick demo video to show you how it works.
I'm founder of Cloud9, so expect extreme bias.
If you are a decent (or better) coder, I have a solution for you. We already have an implementation of XDebug in javascript here: https://github.com/ajaxorg/lib-phpdebug. It might need a bit of updating as it was written for Node 0.6. It does support the latest xdebug.
In addition, we've just released an SDK that allows you to write plugins for Cloud9. Find more info here: http://cloud9-sdk.readme.io/v0.1/docs/getting-started-with-cloud9-plugins. It allows you to install Cloud9 on your own computer or server and you can develop plugins there. You can also distribute your plugin(s) via c9.io and use the SSH workspace feature to have Cloud9 automatically connect to your VM over SSH.
We just released the (pre-alpha) version of the SDK and are actively supporting the handful of developers on the mailinglist here: https://groups.google.com/forum/#!forum/cloud9-sdk.
Implementing a debugger for Cloud9 is actually fairly straightforward. Someone recently built a C++ debugger, which is still in PR here: https://github.com/c9/c9.ide.run.debug/pull/4. You only need to implement one class, the debugger implementation as documented here: https://docs.c9.io/api/#!/api/debugger.implementation. Since there's already an implementation of the xdebug protocol, tying these things together should only be a few days of work.
I hope this helps.

Is there a tool out there that allows debugging of PHP applications line by line? Like how it's done in perl or .net?

Is there an equivalent of 'perl -d' for PHP? I need to step through some complicated unit test and don't want to install any firefox or client/server extensions. Just looking for a line by line execution of my code.
Thanks
Unfortunately, PHP has no internal debugger
There is an interactive shell, but not sure if that will be a good solution for you.
I use VS.php, which is a commercial add-in for Microsoft Visual Studio (2003 through 2010). It includes GDB and XDebug and a local Apache server. It supports step-through debugging as you describe and VS integration including the Locals, Watch, and Call Stack windows.
I understand similar systems exist for Eclipse (for free too, presumably) as well as the commercial Komodo IDE.
make use of Eclipse and choose perspective as PHP.....you r using APACHE for web server....in that you have to add XDEBUG in dll in php EXT folder and made some changes in php.ini and it will work same as .NET debugger......step by step....

php, xampp and debug - can't get to work

I know this question has been asked before and I've looked through the responses but no matter what I do, I can't create an environment to step through my php programs.
I've downloaded the XAMPP stack, and Eclipse and enabled xdebug but nothing.
PHPinfo reports: Debug Build, No.
Does that mean that I'll never get an XAMPP installation to debug. If so is there another Windows, Apache, PHP, MySQL stack recommended?
I downloaded the Komodo IDE 21 day free trial and their wizard can't start debug either.
help
No, the Debug Build phpinfo() refers to is a compile-time switch/define that affects the way php itself is compiled. The debug build is less optimized, contains some more test code and the symbol files, used when stepping through the php C code with a debugger, are more accurate (mostly due to the less optimized code).
It does not affect the ability to add a script debugger module like xdebug. But you need a version of the module .dll/.so that is compatible with your version of php. The API version, Thread-safety "enabled/disabled" and "debug yes/no" information must match. (on second thought I'm not even sure if debug yes/no must match).
Does the xdebug section appear in the output of phpinfo()? If not make sure you've edited the right php.ini. In recent versions of xampp that should be <xampp dir>/php/php.ini regardless of whether you use php-cli or the apache module. But it used to be <xampp dir>/php/php.ini for the cli version but <xampp dir>/apache/bin/php.ini for the apache module of php.
Also check the error.log in <xampp dir>/apache/logs for error messages that might be related. Those should begin with "PHP Startup: ....error message..."
try using wamp if your using windows. It works great for me

Categories