msvrtan's blog

Debugging Uploadify jQuery plugin with XDebug

If you ever decided to use Uploadify jQuery plug-in you might have noticed problems with debugging remote PHP code that this plugin relies on. We all usually do our web development in Firefox ( Firebug rules! ) we started to use Easy xdebug plug-in to easily turn on/off xdebug. This plug-in works by setting cookies for current domain, you can turn it on/off quickly (it is located in bottom right corner) so every request to PHP source while this plug-in is turned on will start a new xdebug session. Great tool for fast debugging of server side code!

Unfortunately setting this up will not work with Uploadify Flash version since calls to remote server side is not done inside browser but inside flash plugin. This is sometimes a nightmare because adding new features or bug fixing some edge cases is a nightmare. You can help yourself by building another form that will use same API but it takes time and energy.

Few months ago I found my self blindly debugging it again and remembered that I read somewhere that xdebug parameters can be sent via GET/POST too. All you have to use is scriptData element and add XDEBUG_SESSION_START & XDEBUG_SESSION parameters with values that you used when setting up your favourite IDE.

To show you how easy it is I will use sample code from this demo :

$(function() {
$("#file_upload_1").uploadify({
height : 30,
swf : '/uploadify/uploadify.swf',
uploader : '/uploadify/uploadify.php',
width : 120
});
});


All you have to add is scriptData param:</p>

$(function() {
$("#file_upload_1").uploadify({
height : 30,
swf : '/uploadify/uploadify.swf',
uploader : '/uploadify/uploadify.php',
width : 120,
scriptData : {
'XDEBUG_SESSION_START': 'default' ,
'XDEBUG_SESSION': 'default'
}
});
});


Heureka! My xdebug session works!</p>

** Dont forget to use values you used in your IDE! **

Before trying this I was playing around with adding this to $_REQUEST, $_POST & $_COOKIE on the beginning of the code but for some reason this doesn't work. Maybe xdebug expects to see this before code starts running but I'm not sure. I hope I helped someone and don't forget not to commit this code into your repository (It can open a whole new can of problems :)).