views:

366

answers:

5

I'm playing with a PHP weblog application using a shared hosting service, as a part of my PHP learning process. The service provider has a typical LAMP environment with remote ssh access.

Vim has been my best friend in exploring the PHP code. However, I found it sometimes hard to trace stuff in the code in case of error. For example, sometimes I visit a page and I got a blank response with no error messages whatsoever. How should I go about debugging this? Any tools that will be helpful?

My experience has been mainly in C/C++, Perl and some CGI programming. So PHP is a very refreshing experience with me :-)

In case it matters, the application I'm playing with is Lyceum, and I don't have much choice on the LAMP environment itself.

EDIT: Free software tools preferred :-)

A: 

Try NuSphere PhpED

+1  A: 

Personally, I would recommend jEdit rather than vim. The SFTP plugin allows you to edit (well, load and save) the PHP documents directly on the server and the PHPParser plugin will give you some error recognition.

Also, if you get a blank page with no error messages, chances are hight that those messages are just hidden from you. Make sure that error reporting is enabled, either in your config or in your code like this:

// Report all PHP errors
error_reporting(E_ALL);

If error reporting is enabled and you still don't see any messages, either enable logging or enable output to the browser.

cg
+4  A: 

I assume your hosting provider configured their PHP installation with display_errors turned off, which is a good thing. That's why you're seeing blank pages. So the most practical solution at the moment would be to have an .htaccess file which turns it on:

php_flag display_errors on

You'd also need error_reporting to an appropriate value:

php_flag error_reporting "E_ALL | E_STRICT"

Anyway, remember to turn this off before letting users access your web site.

For advance debugging I'd recommend Xdebug installed on the server with Eclipse PDT or NetBeans IDE with PHP support as your editor. They both are good clients for debugging, but I really doubt any provider would install Xdebug on their live servers. So you're pretty much left with logging functions if you don't have a development environment.

Ionuț G. Stan
+1 for how to turn on error reporting, though unfortunately xdebug maybe useless on a shared hosting environment because of firewalling and also the difficulty of using an unauthorized extension unless the host allows you to compile and use your own PHP binaries as fcgi/cgi
David
+2  A: 

Getting access to your own local development environment (via XAMPP, for Example) would let you install XDebug.

PhpEd would let you debug it, but also Eclipse's PDT Environment.

Error Tracing and logging via editing php's ini config file is a good way as well, specially if you can manage it to log information. Also, consider adding trace statements and using FirePHP, for example.

aldrinleal
yes - local development is the way to go
Simon Groenewolt
+1  A: 

If you get a blank page, it's probably because of a fatal error, with display_errors turned off. By default, PHP will log errors to Apaches error-log, but you can also configure it to log errors to a separate log.

For debugging, you may also want to look into Xdebug. This extension can do a lot of things, including interactive debugging. You'll need a client to use the debugger, but there is a plugin for vim that does this.

troelskn