I want to dump request variables to a file for debugging. How's this possible?
+2
A:
<?php
$req_dump = print_r($_REQUEST, TRUE);
$fp = fopen('request.log', 'a');
fwrite($fp, $req_dump);
fclose($fp);
Untested but should do the job, just change request.log to the file you want to write to.
46Bit
2010-07-25 05:53:32
Tiny insignificant detail, but Forgot your closing ?>
Josh
2010-07-25 06:00:32
Closing ?> is not necessary, at all. Indeed it's best practice when writing libraries/etc (not that this is relevant here) to omit it so as to ensure no accidental output of whitespace that could mess up output buffering/headers/etc.
46Bit
2010-07-25 06:04:49
I like `var_export($var,true)` personally.
Cole
2010-07-25 06:15:56
@josh A closing ?> isn't necessary, actually its not good practice. You can get extra whitespace after the closing tag which can cause errors in your script
Stoosh
2010-07-25 10:22:24
Interesting note. I learned something new.
Josh
2010-07-26 13:24:55
+2
A:
Use serialize() function for dumping. Dump $_SERVER, $_COOKIE, $_POST and $_GET separately (may go to the same file). If you're planning on debugging with the data it helps to know if the data was part of a POST request or a GET request.
Dumping everything is good for debugging in development, but not so in production. If your application does not have many users, it can work in production too. If you anticipate many users, consider dumping just the $_POST data, or limit server variables to those starting with HTTP_.
jmz
2010-07-25 06:07:29