Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug php scripts at server side? In a situation client page doesn't show response

Tags:

php

I'm currently testing a script on my host. This script is to accept PayPal IPN data, do a couple of things (ie. data verification), send necessary data to a specific email address, and more.

I'm using a test tool on the PayPal site to post test data to my script. My script doesn't work: there should be a code issued but I can't see the error. The test tool in PayPal just does the post and doesn't seem to accept any response. I want to see what happened in my script so that I can fix it. How can I get error messages my script outputs?

Any ideas?

like image 950
Edward Avatar asked Aug 10 '10 11:08

Edward


3 Answers

Not sure if you tested this already (put at the very beginning of your PHP script):

error_reporting(-1);
ini_set('display_errors', 'On');

if it's not showing, try it with an .htaccess (if on Apache):

php_flag display_errors on
php_value error_reporting -1

with this you should get your error. If not, try your server logs or if it's still don't help, try to echo some control values to find where it crash...

Of course this is only for debugging purpose and you should turn that OFF when in production.

like image 105
AlexV Avatar answered Oct 01 '22 18:10

AlexV


A better approach would be to log the errors to a file, and not the 'screen'. If you make a server wide change, it's probable that other sites on the server will be affected.

  • log_errors = On
  • display_errors = Off
  • error_log = /tmp/php.log (or a better path of your choosing; file probably needs to be writable by Apache/webserver).

Failing all of the above, install xdebug and try debugging the code - you can step through line by line and inspect variables at will - perhaps this will give you a better idea.

Failing that, resort to var_dump() and friends.

like image 33
David Goodwin Avatar answered Oct 01 '22 16:10

David Goodwin


In these sort of cases, you should see what the $_POST array is printing in the console. Try using the following code at the very beginning of your page, after initializing with all the required configurations:-

<?php
// include all required configurations
// if needed, include the header file also

echo '<pre>';
print_r($_POST); // for viewing it as an array
var_dump($_POST); // for viewing all info of the array
echo '</pre>';
die();

// other HTML or PHP Logic follows
?>

If this does not work, then you will need to put some breakpoints, by putting some "exit" statements after some code every now & then, and slowly execute as much code as possible in a step-by-step manner.

Hope it helps.

like image 32
Knowledge Craving Avatar answered Oct 01 '22 17:10

Knowledge Craving