Is it possible to Debug with Phalcon PHP? - php

Is it possible to debug Phalcon PHP?
I'm using Sublime 3 editor but am willing to use any editor if debugging is possible.
I found a similar question on Stack Overflow but the only answer was a sales pitch about how great Phalcon is.
Updated: I'm updating this question after the fact. I learned that debugging a Phalcon application is no different than debugging a PHP application except that you cannot debug the actual Phalcon code. I didn't think it was possible to debug at all so my question might have been misleading to other developers that were new to both PHP and Phalcon at the same time.

Unfortunately, since Phalcon is a compiled PHP extension, it's not possible to debug it using a PHP debugger. What we usually do to understand Phalcon internals is having a look at the Zephir source code.
Edit: since my original answer above could be misunderstood. I figured the question's goal was to debug Phalcons internal functions, which is only possible with a C debugger (as described in Luke's answer). Of course it is still possible to debug your own PHP code, but you may not step into Phalcon classes/methods.

I'm assuming that you want to debug your PHP code, not Phalcon extension. If you mean debugging Phalcon framework itself you should install Zephir for code modifying and use gdb to run php command (at least on linux, not sure what about other systems).
Standard var_dump(), echo, printf and die
It works well with all the phalcon objects, just print out variables you want to debug using var_dump() (or other output functions) and use die() before execution your view code. If view part of application get executed will most likely replace your debug printings.
Alternatively you can also pass your variables to view part of your application and just simply use <?php var_dump($variable)?> or if you're using volt just {{dump(variable)}}.
Using XDebug Remote
This is the way I personally like the most. Yes, XDebug Remote works great with Phalcon. Personally I use NetBeans but you can use other IDE's as well. There are many tutorials for configuring all the popular IDEs so I'm not going to write it again. Note that Phalcon team suggests to use XDebug 2.2.3 or greater for better compatibility.
how to configure XDebug on PHP Storm
how to configure XDebug on NetBeans
how to configure XDebug on Sublime 3
You can read more about debuging Phalcon in Phalcon's Documentation

The best way to debug Phalcon based application is to include below code snippet into the bootstrap section of your application AND once you get any error (application level) then you'll get very useful information like below.
Backtrace
Request
Server
Includes Files
Memory (this is very useful)
(new Phalcon\Debug)->listen();

Related

What libraries are needed for an efficient PHP-debugging on Windows SDK?

I just have installed Windows SDK for php-debugging. But now I'm confused a little about which libraries to set for it. I went to https://wiki.php.net/internals/windows/libs but there are lots of them and this questions is not clear for me... What I want just to make an ordinary debugging like to watch which methods are calling while script execution etc. Can anybody give me an advise?
The page you linked discusses the libraries needed to compile PHP from scratch. It does not discuss the thing you are interested in, which is:
What I want just to make an ordinary debugging like to watch which methods are calling while script execution etc
For that, you just need xdebug, which even supplies precompiled binaries for you. You will also need an IDE that speaks DBGp, a debugging protocol used by a number of debugging packages and IDEs.
I found xDebug being best for me. It helps to trace your code and many more. I am using PhpStorm as my IDE. Just configure xDebug in your PhpStorm.

Is there a simple way of setting breakpoints and debug PHP scripts locally in the command line?

I don't know if there is a tool like this for PHP, but I've been using gdb for C lately with great success. I want to be able to set breakpoints and execute a PHP script, then stepping through my functions to check what's going on.
Can this be done with PHP?
If so I'd love some links to tutorials or other resources. I found nothing while Googling.
For the command line there is an excellent tool called phpdbg:
Features
Stepthrough Debugging
Flexible Breakpoints (Class Method, Function, File:Line, Address, Opcode)
Easy Access to PHP with built-in eval()
Easy Access to Currently Executing Code
Userland API
SAPI Agnostic - Easily Integrated
PHP Configuration File Support
JIT Super Globals - Set Your Own !!
Optional readline Support - Comfortable Terminal Operation
Remote Debugging Support - Bundled Java GUI
See here for some tools:
xDebug
http://www.ibm.com/developerworks/library/os-debug/
http://www.tek-tips.com/faqs.cfm?fid=6379
xDebug certainly provides the ability to set breakpoints.
source
Tool for PHP code analysis

How to debug PHP application using Eclipse PDT (xdebug and zend debugger)

I'm working on one application.
I am using Eclipse php Helios IDE for developing php application.
I wanted to know below things related to this IDE, so that i can implement PHP application instantly as well as very efficiently :
1) How to do remote debugging using Eclipse PHP Helios IDE
2) What is the pros and cons of xdebug and zend debugger
3) Which debugger should we use from xdebug, zend debugger.
4) Is there any other debugger available apart from above two mentioned.
Below links i refered for above mentioned debugger.
1) http://devzone.zend.com/article/2930-Debugging-PHP-applications-with-xdebug
2) http://www.eclipse.org/pdt/documents/XDebugGuideForPDT2.0.pdf
3) http://www.xdebug.org/
I am not getting exact information in above URL's,
as I mentioned specific query above those are needed.
Is anyone know any reference, please suggest me.
Thanks !!
-Pravin
I use the Galileo release, rather than the later Helios release, but I suspect they're very similar in this regard...
The answers to your questions would fill quite a reasonable chapter in a book, so instead I'll point you towards some excellent links on the topics;
2) This article is a great post on the pro's and con's of each with Eclipse; Eclipse debugging with Xdebug and Zend Debugger comparison. Personally I always use xdebug since it has additional features I like, and as I don't use Zend I am not interested in any integration benefits it may offer.
3 + 1) However, there's nothing to stop you installing both and switching between them using different "server setup" configurations inside Eclipse. This post shows you how to set them up on different ports to allow this; Debugging PHP using Eclipse and PDT
There is a small catch (to either debuggers) in that if you use apache mod_rewrite (or similar) for pretty URLs, you have to be really careful to ensure the rule still passes the debug parameter as a GET value in the URL. I'm not personally aware of any way around this (e.g. via cookies).
4) Not that I'm aware of under Eclipse.
Happy reading....
Step by step Debug process using XDebug and Eclipse Helios . Hope it helps.

How to debug a PHP application?

Which is the best way to debug an PHP application as we can debug ASP.NET application with Visual Studio ?
I'm using the IDE Eclipse PDT, which can use the PHP extension Xdebug to provide debugging functionnalities, kind of the same way as Visual Studio (a bit less powerful, maybe), which gives you the ability to do things like :
step by step
step in / out of functions / methods
see the content of variables
have a stack trace showing where you are
That's really nice to debug big programs -- especially ones you didn't write, to understand how they work (or don't ^^ )
It can also use the extension "zend debugger" ; but I've never tried this one.
Even without using a debugger like the one provided by PDT, Xdebug is a nice extension to have on a development server : it gives nice stack traces when there's an error/exception, it allows you to get nice-looking var_dump's output, ...
It can also be used to get profiling data, which you can visualize with tools like KCacheGrind, WinCacheGrind, or Webgrind.
But note it is hurting performance badly, so it definitly should not be installed on a production server !
PHP Console is good if you want to debug WEB 2.0 (AJAX) web-projects.
PHPEd is great for this, but you have to pay for it.
xdebug works, but you have to install it on the server. I haven't used it, but it seems to have a good reputation.
Some IDEs (Aptana/Eclipse + PHP springs to mind) then can interface with xdebug.
XDebug with Eclipse PDT is the best I've seen. Here is a tutorial on setting this up:
http://devzone.zend.com/article/2930-Debugging-PHP-applications-with-xdebug
NetBeans also has debug capabilities. From the website:
You can debug scripts and web pages, either locally or remotely. The NetBeans PHP debugger integration allows you to map server paths to local paths to enable remote debugging.
I use the Zend debugger and after trouble getting it working (it was a remote setup with he server and the development machine both virtual!) - it made a huge difference to my development efficiency. If you are converting from Visual Studio you will find quite a few things different and even difficult. It is worth sticking with it and mastering howewever - I can now set breakpoints in arbitary pages and navigate to them just like the user, stop and examine locals etc and then step through what happens - put simply now I can find bugs whereas without it I was guessing. Also see Developing with PHP and Eclipse (Galileo) which I found helpful.
PHP storm is a good one from JetBrains.

Other packages with Xdebug-like features (informative PHP errors, formatted var_dump()s, etc.)?

When Xdebug is installed/enabled, standard PHP errors (when set to display in the browser) are replaced with more informative messages that include stack traces for each. Also, I've noticed that it also seems to improve output in other areas such as the var_dump() function, formatting/color-coding the output to make it more readable.
Are there any 3rd party packages that offer similar functionality? I tend to prefer using Zend Debugger for debugging and would love to find something like this that doesn't depend on Xdebug. Certainly I could write my own error handler, a custom var_dump() function, etc., but I would love to find something that transparently integrates itself into PHP the way Xdebug's functionality does.
Edit: I should emphasize that I'm not looking for a debugger, but for the "extras" that Xdebug offers.
As for your debugging you'll only find access through PHP extensions, regardless of what IDE you are using.
Xdebug is the most popular due to it's extra features, beyond that of what you've even described. Xdebug will do profiling (tracing) into the valgrind format that you can use programs like Kcachegrind and wincachegrind to evaluate.
Your only other real alternative to the debugging facilities Xdebug provides is Zend Debugger which is a part of the Zend Platform (again available as an extension).
As for the replacements, you won't find any other extensions that do the var_dump and error reporting replacements. And especially won't find (beyond Zend Debugger) a debugging protocol, and definitely won't find any other extension that does profiling.
dBug offers quite a nice replacement for print_r:
http://dbug.ospinto.com/
Try NuSphere's PHP IDE. It has an integrated debugger also, and you can get a demo version free if you like.
http://www.nusphere.com/
Shameless plug of my own var_dump alternative:
http://raveren.github.io/kint/
Screenshot:
(source: github.io)

Categories