Messages are sent to the parent by appending them to the tempfile.
function sendMessage( args ){
    last = new Date();
    fs.write( tmpfile, JSON.stringify( args ) + '\n', 'a' );
    // Exit when all done.
    if( /^done/.test( args[0] ) ){
        phantom.exit();
    }
}