Xdebug debug with Netbeans on Linux

XDebug is a free PHP extension to debug variables of your applications. Combined with Netbeans for PHP debug features (break points, variable watching and flow execution navigation, see screenshot on the left), it allows to have a complete debug environment.

What it’s really interesting is the possibility to place breakpoints in any file, even though not called directly in the local URL. That is required when working with web applications with URL routing/rewriting sudh as MVC applications (Zend Framework, Symfony etc..)  where the PHP code in a controller action does not match with its path in the local URL.

Here are the easy steps to follow in order to configure Xdebug for Linux Ubuntu 10.04 LTS. I’ll write the full commands to make it easier by copy & paste.

-) download the xdebug extension

sudo apt-get install php5-xdebug

-) check where the extension is installed

sudo find /usr/lib/php5 | grep xdebug

-) open the php.ini file (inside apache)

sudo vim /etc/php5/apache2/php.ini

and add these lines at the end of the file (replace with the right module path)

[xdebug]
;zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so
zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

note1: xdebug.so could be elsewhere. use find /usr/lib -name xdebug.so to find the correct path
note2: see other xdebug settings

-) restart apache

sudo /etc/init.d/apache2 restart

-) Netbeans: tools->options->PHP
Tick ”Watches and Baloon Evaluation” (*), Untick “Stop at first Line” (not really useful except when debugging the application bootstrap).

(*): Xdebug is unstable with this options, however I found it very useful and enough stable for my purposes. It’s possible that Netbeans crashes with the current version, restart it in case.

5) Netbeans: right click on the project ->properties->Run configuration -> run as local website. Insert the (virtualhost) local URL. Do not insert any index file if the application uses URL routing, or Netbeans will launch the relative script path in the URL.

6) Netbeans: place your breakpoints by clicking on the line number, then start the debug (Under Debug->debug or Ctrl+F5). Netbeans will open the browser at the local URL, and when reaching the breakpoitns, netbeans will show a red icon on the line.
Depending on the browser, the focus will return to Netbeans (go manually if it does not).
Select the code / expression to watch/evaluate. Netbeans will show a baloon tip with the value. Alternatively, right click and select “new watch” to have the expression and the values appearing in the debug panel.
Use F5 to go to the next breakpoint, F7/F8 to step into/over.

As mentioned, Xdebug is unstable with the option set in the step 4. If watching some expressions crashes netbeans, use the “new watch” option instead.

Post to wordpress using Zend_XmlRpc Client

WordPress supports metaWeblob API standard to post data into the blog from an external service.

WordPress contains xmlrpc.php [source], that is basically a XML RPC server that can be called from a client that posts XML RPC messages.

See here the wordpress codex guide.

Sending XML message is a task very easy with zend framework xml rpc libraries. It automatically creates data types using a straightforward conversion, e.g: php array->xmlrpc array and php associative array->xmlrpc struct.

Here is an example to post data to a wordpress blog

require 'Zend/XmlRpc/Client.php';
$client = new Zend_XmlRpc_Client('http://www.softwareengineeringsolutions.co.uk/xmlrpc.php');
$res = $client->call('metaWeblog.newPost',array(
        0, //blog_id, keep 0 for standard wordpress
        'xx', //username
        'yy', //pass
        array(
            //'post_type' => 'post', //not necessary, 'post' is default
            'title'=>'test xmlrpc',
            'description'=>'description of post',
            'mt_keywords'=>'key1, key2',
        ),
        true //publish
    ))

To see the detailed options, see the API documentation or see the xmlrpc.php source directly to better understand the data supported by wordpress (more than the standard metaBlog API data)

PHP vs JAVA developers

JAVA developers sometimes tend to look down on other developers, including PHP developers. I think that is mainly due to ignorance of the current state of things and fear of seeing a competing technology growing so fast and being adopted more and more for a wide range of applications on the web.

Another explanation is in a book I’ve recently read “php|architect’s Guide to Enterprise PHP Development” (a book I suggest to developers that work on considerably big projects).

“You can safely say that while PHP is easy to learn, it is more difficult to truly master the language.
If we compare this to a language such as Java, we notice that Java has a ’natural barrier’; programming Java takes a certain amount of programming skill, so it is not a language that anyone can easily learn. This means that, even though the best PHP programmers can compete with the best Java programmers, the least skilled Java developer is probably still a better programmer than the least skilled PHP developer.
The range between high and low quality is simply bigger for PHP. This is one of the reasons why PHP sometimes has a negative image;  PHP is for hobbyists and not to be taken seriously. But this is not the case; it simply means that you need to be careful what software you use and who you hire as a developer”.

Well said Ivo Jansch