AJAX and PHP End-to-End Debugging

Cal Evans at the Zend DevZone just posted my screencast on AJAX and PHP End-to-End Debugging.

I mentioned in the screencast that I you could find some information on my blog that is used in the video, so this is that post.

Based on this post by Greg Beaver you can debug AJAX applications with the Zend Debugger by simply taking the QUERY_STRING as he mentions and placing it as GET arguments for your AJAX request.

start_debug=1&debug_host=YOUR IP&debug_port=YOUR DEBUG PORT&debug_stop=1

for example:

start_debug=1&debug_host=192.168.0.102&debug_port=10000;debug_stop=1

In context, this looks more like (using Prototype):

<?php
// We need at least one line of PHP
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
?>
<html>
    <head>
        <title>AJAX End-To-End Debug Demo</title>
        <script src="http://pixelated-dreams.com/js/prototype.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript" charset="utf-8">
            function doAjax()
            {
                debug = "?start_debug=1&debug_host=192.168.1.201&debug_port=10000&debug_stop=1";
                options = {method: "post", parameters: Form.serialize($('hello'))};
                new Ajax.Updater('response', '/ajax_debug/ajax.php' + debug, options);
            }
        </script>
    </head>
    <body>
        <div id="response"></div>
        <form name="hello" id="hello">
            <label for="name">My Name is:</label> <input type="text" id="name" name="name" />
            <button onclick="doAjax(); return false;">Hi!</button>
        </form>
    </body>
</html>
?>

The file ajax.php looks like this:

<?php
if (isset($_POST['name']) && !empty($_POST['name'])) {
    echo "<h1>Hello " .htmlspecialchars($_POST['name']). "</h1>";
} else {
    echo "<h1>Ut Oh! I think you're having an identity crisis!</h1>";
}
?>

Hope you enjoy the screencast!

- Davey

Comments are closed.

Twitter

@spooons you need a quick-release plate? http://amzn.to/9vUIeU

@dshafik [6 hours ago]

@a add in Ctrl and it will not do the ticks (also works normally)

@dshafik [9 hours ago]

I came as Carl Fredricksen to "Dress like your favorite movie character" day at work... http://www.flickr.com/photos/dshafik/4951158377/

@dshafik [10 hours ago]

Books & Things