/ Published in: PHP
I'm originally a sys admin and i love "tail - f /var/log/*" ... so i created a similar function in PHP that will allow me to view in real time what classes/functions/files/lines of my code is being run...
The usage is really simple, just set a global variable "debug" to true/false...
Note: The usage of this function will slow down your script... use it only to debug. Turn it off on production.
to view the logs, go to your default php error log file. Enjoy!
The usage is really simple, just set a global variable "debug" to true/false...
Note: The usage of this function will slow down your script... use it only to debug. Turn it off on production.
to view the logs, go to your default php error log file. Enjoy!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Do you want to debug? // Include this function to your functions.inc.php or whatever shared libraries you are using. function debug($trace,$query = null){ if(debug){ } } } function shutdown() { global $start_time; } // Add the following lines in every function: if(debug){ } // Examples: function clean($string,$type){ if(debug){ } doTask(); } // You can also log all the queries you are using by using debug($query) like this: function selectQuery($query){ if(debug){ } return $result; } // Result looks like this: [12-Nov-2010 11:43:36] Initiating class: Db [12-Nov-2010 11:43:36] Calling function: dblink [12-Nov-2010 11:43:36] @ line: 8 [12-Nov-2010 11:43:36] --- [12-Nov-2010 11:43:36] Initiating class: Db [12-Nov-2010 11:43:36] Calling function: selectQuery [12-Nov-2010 11:43:36] @ line: 76 [12-Nov-2010 11:43:36] Performing Query: SELECT * FROM user WHERE email = '' AND verified = '1' LIMIT 1 [12-Nov-2010 11:43:36] --- [12-Nov-2010 11:43:36] Execution took: 0.0076 seconds.