How a framework development works without a debugger? - php

I am quite new with development. In some programming language such as python and PHP there is not a good debugger. How is the development going on without a debugger? just put the logs in the source code? Especially for the framework developers, how do they test their codes?
Thank you very much.
-Stefan-

Your answer concerning the debugging in Python is truly nonsense. Python has a reasonable "pdb" debugger which is useful since years. Apart from that you can have a powerful IDE as WingIDE giving you all debugging and inspection power you need. Making such wild claims about Python is not appropriate. That's why this question deserves a clear downvote.

You don't seem to have looked around before coming to your conclusion. I've worked with two excellent debuggers for PHP. Xdebug and ZendDebug. If you have an IDE like Eclipse or NetBeans (both free), it's super easy to debug your app. Just click on the debug menu button :)
Xdebug : http://www.xdebug.org/
Zend Debug : http://www.zend.com/en/community/pdt
Eclipse PDT : http://www.eclipse.org/pdt/
Netbeans : http://netbeans.org/

Python has a debugger: pdb. If you use Werkzeug, then you can also access each frame of a stack trace and debug there on an error

I am not a python developer, but in case of PHP,we do have a debugger. Setting it up and getting to work with it might not be as easy as C# (with VS) or other programming languages. PHP itself is developing and becoming better.
Putting logs is very important and good way to debug. You could also have some print statements, for debugging. Apart from that, you can make use of PHPeclipse IDE and use the debugger. This will help you create breakpoints etc..
You could also setup error reporting in PHP.
Refer to this article for setting up you development environment.

python -m pdb foo.py
And even without using that, usually you get detailed tracebacks when an error happens so many people don't know about pdb because they can just read the error message containing everything they ever wanted to know. It's not like C where it just goes boom and says "Segmentation fault" and leaves you with nothing to work on.

Related

Is it possible to Debug with Phalcon 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();

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.

Remote Debugging and Memory Profiling in PHP

Two Questions
How can I debug PHP code remotely which is lying on the server, currently I am using var_dump's to check the value of variables ?
How can I see how much memory and how much time particular function is taking to execute remotely which is lying on the server, any suggestion for good profiler for this ?
Note: I am talking about code which is lying remotely on the Server.
Like others said, Xdebug is your best bet. I'll just chime in here and mention a couple profilers. If you're on Linux you can't go wrong with KCacheGrind and on Windows it appears WinCacheGrind is what you'd use. I was not aware of remote profiling being an option, it dumps to a file which you'd need to have access to. Although, it appears you are accustomed to that already.
Komodo is a pretty nice IDE with Xdebug support (debug requires paid version), although there is no reason to not just install Eclipse and pick up the Zend PDT.
My suggestion, program in Python and be a happier developer (more developer-friendly modules/tools) :P
I think Xdebug is what you're looking for. If you don't mind spending the money, Zend IDE for Eclipse comes with Zend Debugger and it works quite well also.
As bender said: XHProf [1]: http://pecl.php.net/package/xhprof [2]: http://mirror.facebook.net/facebook/xhprof/doc.html is much lighter then XDebug and I prefer it for taking profiling info about the live site. Facebook uses it for profiling their live servers. It has nice features like aggregating the profiles and making diffs between them so you can see the regression in your code as well. If you need step by step debugger then XDebug is your call. Just be aware that XDebug on live site turned on by default imposes important degradation of performance, and output cachegrind files that site generate could fill the disk very fast.
I suggest not using XDebug on live site and if needed configuring it to activate on demand through trigger as described in docs http://xdebug.org/docs/
Configure your server to allow XDebug remote debugging and pick a client, although it can be a bit involved to set it up. I've personally used Geben for emacs as a front end for XDebug, but there are many choices.
As far as you're allowed to install stuff on the server Xdebug is the way to go for both debugging and profiling.
If you are on a shared server forget about it (unless you are a good friend of the server admin). Your best chance seems to be FirePHP - for debugging only. You may want to take a look at dBug too; it's basically a prettied up var_dump, but your eyes will be grateful for it.

To visualize the sequence of PHP codes

Is there any tool by which you can visualize the sequence of PHP code such that you can avoid mistakes such as here?
I had an idea that the code later in my PHP code will overwrite the code at the beginning. However, this was not the case in my case.
I'm not sure I truly understand the question, but one solution might be to use a debugger ; a nice way to do that is with
The extension Xdebug, which can be used as a debugger
and some graphical IDE that integrates some debugging tools, like Eclipse PDT
Both of those are free, btw.
With those, you can do step by step, set up breakpoints, watch the content of variables, view stack traces, ... And it works both for Web and CLI scripts ;-)
Of course, it means having Eclipse running on the machine you are executing your script... But if you are executing it on your development machine, you probably have a GUI and all that, so it should be fine...
(I know that, for web applications, you can have Eclipse running on a different machine than the one with the PHP webserver -- that's what is called "remote debugging")
Obviously, you probably won't be doing that on your production server, but, as long as you are on your development machine, using a debugger sometimes really helps understanding what the frak is going on ^^
I've been using Drupal these last few month ; using a debugger was sometimes the only "sane" way of understand what called what and how ^^
Disclaimer : to be honnest : a large part of this answer is a re-post of an answer I did to another question a few days ago.

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.

Categories