html/php debugging - php

I am starting a website, thus I'm learning how to program in html/css/php. For other languages I have learnt so far, there has always been an IDE or interactive console that I can type in codes directly to see how they works, access variable types etc., which makes learning and debugging a breeze. (E.g. bash, python, matlab, perl, tcl...)
Can I do the same for html and php? In the spirit stackoverflow's questions style, lemme try to make the questions a little more specific.
I know I can use php interactively on a terminal.
But that is insufficient if I want to see how it works in a html script.
Is there a browser/IDE with a console where I can input commands interactively and see the results?

For PHP:
I'd suggest to use Xdebug.
Read through this article: Debugging techniques for PHP programmers.
Note about debugging production.
For your markup:
Read Firebug-like debugger for Google Chrome.
Also, you might try Web Developer extension.

I find enabling errors is handy for general debugging. With it enabled you can see where the script failed and hone in on the error quite easily. For more advanced stuff Xdebug has it's place.
Combined with a local WAMP installation you have a great start point. Save the php script, execute it and combined with "Firebug" (FF extension) and you have a decent "beginners" tool set for debugging.

you can make your browser your ide. i do, check it out:
handy article showing how to output php to browser console. http://sarfraznawaz.wordpress.com/2012/01/05/outputting-php-to-browser-console/
as for html, download web developer extension for your browser, and validate your markup to test/debug.

You might be interested in something like Cloud9 IDE.
Check them out at: www.cloud9ide.com

Related

Testing Tools for PHP

any good open source/commercial PHP testing tools available??
I don't know exactly what do you want to test but here are some tools which help during development:
PHPUnit for unit tests
CodeSniffer for coding standards
PHP Mess Detector for code quality
For testing a web application within your web browser automatically try Selenium.
I can also recommend FirePHP with will enable you to debug your code using the Firebug plugin for Firefox.
A list of PHP Performance Test Tools in this link http://scriptime.blogspot.in/2014/07/performance-test-tools.html
Check out PHPUnit:
http://www.phpunit.de/
One especially handy tool to debug is xdebug. Install through PECL. Integrated with your IDE you'll be able to interactively step through code. Without the IDE and it'll prettify your errors and help you test them.
For automatically testing the app itself, Selenium seems to be the best choice. Note that I don't use it, but it will automatically simulate going to a page, filling in data on a form, etc. It's basically a way to automate users' activity in a browser.
The other suggestions are all apt as well.
To test the code you should write unit tests. This requires two tools, what you need is a debugger (xdebug or zend debugger) and phpunit. They can be written in any editor. If you haven't done this before here is an intro article.
http://devzone.zend.com/article/2772
To test the output of the code (HTML,CSS,JS) you should use a different tool. A GUI testing tool is what you use for this job. Here is a list of these tools. Selenium and Selenium based tools is probably the way to go, but the best decision depends on the company and lack thereof.
http://en.wikipedia.org/wiki/List_of_GUI_testing_tools
Do you mean a site where you can run PHP code in order to test it? Like localhost?
OK, I'll give you an answer without the smarm :-).
Here, get started with XAMPP http://www.apachefriends.org/en/xampp-windows.html. I don't know of any in-browser PHP testing methods, and I can (off the top of my head) think of several ways that a good coder might exploit a site that uses eval() to run user-submitted code. They'd basically be giving anybody free range to run code on their server. But look...get started on XAMPP and there you can start testing PHP scripts without even needing an internet connection. Also if you're interested in a good PHP beginner's guide, see here:
http://www.tuxradar.com/practicalphp
Not sure if this is for debugging or for testing but i found WAMP to be a good alternative to XAMP. Thats what i use for testing

How to do Debugging of PHP?

how we do basic debugging in PHP ?
Can anybody share true horror story on debugging PHP application (or (even better) on PHP framework such Codeigniter and Wordpress) ?
i love to hear real experience in case i have to encounter similar situation on my journey to learn PHP.
XDebug may be used to debug a PHP application. Basically you install this on your server and configure it in PHP.ini. Then on your desktop machine, you can setup Netbeans (and maybe Eclipse, but I have not tried that) to remote debug. When you are in a remote debug session you can do any of the things you typically expect: set breakpoints, step through code, etc.
One major annoyance when using CodeIgniter with mod_rewrite is that the debugger gets confused by index.php not showing up in the URL. I am not sure if this is a problem on the client side or server, and whether CI "eating" the GET portion of a URL has anything to do with it. In any case, I have worked through it by copying a 'debug.php' file to the server and starting debugging with that file - everything seems to work fine after that.
I any case, I highly recommend you get setup with XDebug at some point. You may not use it everyday, but when you need it you'll be thankful you did your homework ahead of time.
Easiest option (without installing any IDE) is to use firefox FirePHP addon.
Download and install FirePHP firefox addon
Download FirePHP core library from their website
Extract FirePHP library you downloaded in step 2 and only copy FirePHP.class.php to CodeIgniter /application/libraries/ folder, but give it a name FirePHP.php without the class part
Turn PHP’s output buffering on
Start your Firefox, click the FireBug icon on the bottom lower area, or go to menu and select tools. After you turn on (set them to enable) FireBug and FirePHP, be sure to click on the Net tab next in line to HTML, CSS, Script, DOM and set it also to enable.
See this link for how to use firephp library: http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/
There is one problem in using IDE debugers - it's bad for debuging AJAX applications. In this case you will need to use some of browser extension. For FireFox it's FirePHP, and gor Google Chrome it's Php console.
I checked out a lot of debuggers 2 years ago when I wanted to set up a debugging environment for myself in PHP. I posted a brief post on this, you can go through it http://forums.codewalkers.com/general-chat-93/which-php-ide-to-use-840352.html
Bottomline was that Nusphere's phped was the best and its debugbreak() function makes debugging a real bliss. With codeigniter also this works fine, no tweaks required if you have already enabled get variable. The only hiccup with codeigniter+phed is that, you cannot do code navigation like "right click and find declaration" for other files models.
Off late I have been checking out codelobster they have a codeigniter plugin, but I am not through with it yet.

REMOTELY Debugging PHP Using Eclipse

I'm a self-taught noobie, trying to debug PHP on my GoDaddy hosted server. Is this idea even rational, or do I need to continue to do all development locally and just continuously re-ftp upload the changes?
Is there some way that I can use eclipse to step through, and debug my php scripts that are hosted on a third party site?
Although I have only used Netbeans and XDebug for remote debugging, it should be possible to use Eclipse PDT and XDebug. See:
setting-eclipse-pdt-and-xdebug
Debugging PHP applications with xdebug
One caveat, however. To configure xdebug you will need to modify some settings in php.ini - I am not sure if this will be possible on a hosted server. If not, you would need to have a local server that you use for debugging, and would need to figure out another solution for your "production" environment. Which may not be a bad idea, actually, as it would give you a good place to test your changes without risking breaking anything on your actual site.
Also, I recommend that you look into Netbeans, if for no other reason than to experiment and see what it can do compared to Eclipse. One nice feature is that you can set it up to automatically ftp (or scp) changed files to the remote site. So you can make some code changes, click the debug button, and after waiting a moment for your files to upload you can be stepping through code on the remote site.
While there is definitely a case for remote debugging you should always be working locally and then uploading. Anything except the most minor of changes should be done locally tested then pushed to a server - sometimes production directly, sometimes a testing server...
Yes Eclipse supports remote debugging with Xdebug as well as the one from Zend Debugger check out Justin's links as well as This one for Zend Debugger. I think Zend has an all in one with pdt+deps and Zend Debugger - ofcourse you still need to set up the extension on the server (note link is for setup on windows but hte process should be similar).
Obligatory "Ewww GoDaddy" :-)
If the web server have XDebug installed, then you can do debugging with it. Searching for it in google yield a quite num of articles on how to do it.
Personally, I'm using CodeIgniter. I do debugging using FirePHP and PQP. Make a habit to write a good indented code. You might find your code have less bug, both syntax and logic, and easier to maintained in the future. Use a consistent white space, either tab or space. Use a consistent bracket style. It will save you from the headache when re-read it for bug or adding more feature later.
I have never needed to do a step by step debug in PHP, but when I do need to debug I just output strings of the variables at that point.
However, one thing that I found, but again never used, was FirePHP:
http://www.firephp.org/
As far as I'm aware, this is not possible in Eclipse, it is, however, possible in NetBeans, but as Nathan stated, I've never really needed to remote debug any of my PHP scripts.

Debugging PHP

I've been using xdebug to debug and understand code in php projects for a while now, and have sometimes come into situations where it's been unclear what's going on inside of PHP.
Is it possible to set xdebug or gdb up so that i can trace into actual php builtin functions?
If you are using a macosx, solaris or recent freebsd system you can throw a little dtrace at it. It can come in handy for those all too numerous "WTF is PHP doing?" moments.
I doubt it, xdebug is intended for tracing your PHP code, not the internals. The internals are assumed to be bug-free (which obviously they aren't sometimes, but that's beyond the scope of xdebug).
You can always look at the PHP source if you want to know what the built-in functions do, but that's sometimes pretty hairy. The PHP manual docs have always served me well enough when I want to know what they'll do.
You can use gdb to trace in to the C-level code, provided you have php compiled with debug symbols. Have a look here for a start:
http://derickrethans.nl/phps_segmentation_faults_gdbfu.php
One way to test the output of the Zend engine, to peek inside at the opcodes, you can use Derick Rethan's VLD (Vulcan Logic Dissasembler), which also appears to be on PECL. Note: only works on *nix systems (see site for requirements).
Some examples of debugging these opcodes can be found on Sara Golemon's blog, in articles such as Understanding Opcodes and How long is a piece of string?.
There is also great Google Chrome extension PHP Console with php library that allows to:
See errors & exception in Chrome JavaScript console & in notification popups.
Dump any type variable.
Execute PHP code remotely.
Protect access by password.
Group console logs by request.
Jump to error file:line in your text editor.
Copy error/debug data to clipboard (for testers).
Recommend to everyone!

PHP Console that doesn't require heavy installation or a desktop app?

I'm looking for clean way to break my current habit of using print commands in PHP when I want to see what's happening.
I am aware of options such as Zend Debugger but I use Coda for development and I'm not interested in mixing other software or having to do server commands. I just need a console that can be added to my codebase and then turned on/off.
Does anything like this exist? Furthermore, what do you use and why?
EDIT: There was a lot of stuff out there but I needed something even simpler so I ended up coding it myself. It didn't take long (nor is it very pretty) but I've put it up on my server for anyone else interested.
There is very good extension for Google Chrome - PHP Console.
You can use Xdebug in combination with any one of the many options available to view its debugging info.
There's FirePHP which will write your PHP log messages to the Firebug console.
I am aware of options such as Zend Debugger but I use Coda for development and I'm not interested in mixing other software or having to do server commands. I just need a console that can be added to my codebase and then turned on/off.
Not entirely sure if I understand you there, but couldn't you log to a file and then have a console window running with tail -f /path/to/log-file.txt? That works pretty well for me. Of course, you do need a console connection to the server for this.
Using Coda? That means you are using a mac. You probably want to look at XDebug and http://www.bluestatic.org/software/macgdbp/
There is another extension for Chrome available called ChromePHP. It's a little simpler than some of the other solutions:
https://chrome.google.com/webstore/detail/noaneddfkdjfnfdakjjmocngnfkfehhd
Getting started guide available at:
http://www.chromephp.com
During my development career i have not stumbled upon a software that displays the output you describe in your question. It would be a wonderful program or feature i believe but sadly i have not found any.
Like Andrew and nickf have answered, there are some good tools out there and until someone sits down and writes this, it looks like we are out in the cold.
I was looking for similar solution which wasn't heavy and even better I didn't need to include any classes, so I created simple function that outputs php to browser console, you can check it here:
Outputting PHP To Browser Console

Categories