Results 1 to 9 of 9

Thread: Debugging AJAX server side with php

  1. #1
    Join Date
    Sep 2006
    Location
    Maryland, USA
    Beans
    260
    Distro
    Ubuntu 12.04 Precise Pangolin

    [Solved] Debugging AJAX server side with php

    I've got some code that I am using to alter for my own - and it uses AJAX and Json - however, when you use Json, you apparently can't use print or echo to do debugging on the server side in PHP. I found a nifty package called FirePHP that's an extension of Firebug, but that requires PHP 5.2.5 which hasn't been backported.

    Does anyone have a suggestion about server side AJAX using Json debugging tools?

    Thanks
    Last edited by matthewboh; September 30th, 2008 at 02:00 PM.
    Impari Systems, Inc
    http://www.imparisystems.com

  2. #2
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Debugging AJAX server side with php

    ... because AJAX/Json runs not on server but in client's browser?

  3. #3
    Join Date
    Aug 2006
    Beans
    44

    Re: Debugging AJAX server side with php

    What sort of thing are you needing to debug? Surely any script you run via an ajax request either returns something back to the client or performs a function on the server like updating a database which you can check?

    If you need to debug your php, just run the script directly in a browser passing in the data directly via post or get rather than using javascript. If you need to debug the javascript you can do that client side in a number of ways, easiest probably being alert().

    Unless i'm misunderstanding the problem?

  4. #4
    Join Date
    Sep 2006
    Location
    Maryland, USA
    Beans
    260
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Debugging AJAX server side with php

    What I'm trying to do is find out where my code is bombing in the php script that runs on the server.

    Basically, I send a request to the server to have it lookup a username / password combination - and it's just not working. Basically, I borrowed code that has worked flawlessly. The only change I've made is in the database name - which shouldn't harm it.

    Anyway, you can't use echo or print to put out messages because it breaks the json headers, so I've been trying to use PHPEclipse and Xdebug - but just running into more problems with trying to set the parameters to run it. I've been googling most of the day, but haven't found the secret to debugging PHP code that's called with AJAX.
    Impari Systems, Inc
    http://www.imparisystems.com

  5. #5
    Join Date
    Mar 2006
    Beans
    199

    Re: Debugging AJAX server side with php

    One simple way: write your debug output to a file so you can then go and examine it.

  6. #6
    Join Date
    Sep 2006
    Location
    Maryland, USA
    Beans
    260
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Debugging AJAX server side with php

    Found a way! Using Firebug 1.2.1 and PHPEclipse together. There's also FirePHP, but that requires PHP 5.2.5 and I just don't feel like installing that from source. Thanks everyone!
    Impari Systems, Inc
    http://www.imparisystems.com

  7. #7
    Join Date
    Apr 2006
    Beans
    1,030
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Debugging AJAX server side with php

    I do this at work:

    tail -f /var/www/name-of-your-site-folder/log/error_log

    then I open fire bug and watch whats being sent and received via the xml request.

    between those two you can usually see whats going on.

    Mike

  8. #8
    Join Date
    Feb 2008
    Location
    Cape Town, South Africa
    Beans
    Hidden!
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Debugging AJAX server side with php

    Quote Originally Posted by Mickeysofine1972 View Post
    I do this at work:

    tail -f /var/www/name-of-your-site-folder/log/error_log

    then I open fire bug and watch whats being sent and received via the xml request.

    between those two you can usually see whats going on.

    Mike
    Ye at work I have a log tailer running on the one pc perminatly..

    Use this instead of echo/print to view debugging info. www.php.net/error_log

  9. #9
    Join Date
    Apr 2007
    Location
    Bay Shore, NY
    Beans
    195
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Debugging AJAX server side with php

    Hi,
    I came to this thread because I have the same problem. If you are using Ubuntu server with Apache, then you can use something like this in your php code to debug:
    Code:
    function() or error_log("error message here");
    then you can find these error messages in the /var/log/apache2/error.log file. access this file by using the command line code:
    Code:
    tail /var/log/apache2/error.log
    Last edited by Jefferythewind; July 1st, 2011 at 01:18 PM. Reason: code correction

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •