1

Is it possible within a PHP script to start a trace log and activate a debugging log. I am not looking for eclipse + xdebug, but something like this use-case: When script starts, it checks if $_GET["debugme"] is set. If yes, say start_trace_log(). Anything that happens after that in the rest of the script, should be logged, e.g.

scriptA.php :10 include("anotherscript.php")

anotherscript.php:1 foo()

...

At the moment, I have to manually do this for any script that i am interested to log and everywhere the script has to check $_GET["debugme"] instead of simply debugging ALL within this script run. Very uncomfortable for ocassionally checking scripts.

Any better ideas or comfortable ways of tracing php scripts from a start point to the last line?

1
  • On SO, if you have bits of code inside normal text you can use inline highlighting by surrounding the code in backticks (`). Commented Jun 18, 2012 at 13:06

3 Answers 3

1

Add this line to the end of the end or footer script:
if(isset($_GET["debugme"]))debug_print_backtrace(); that will print details like #... function-name() called at script-path.php:linenumber.

Don't forget to estrict the debugme feature to run on development system only!

Sign up to request clarification or add additional context in comments.

2 Comments

@Thiem Nguyen: this edit changed the semantics and is wrong now. The output really looks like this: #... function-name() called atscript-path.php:linenumber
rollback-ed :) sorry for my mistake
1

phptrace may be a better choice cause you needn't to change your script and you can trace at anytime you want.

Comments

0

Although I find it highly annoying when this is used in production, you can throw this bit of code:

if(isset($_GET['DEBUGME'])) {
    start_trace_log();
}

Into a file, and then adding that file to your PHP auto_prepend_file so it gets run at the start of every PHP script.

Of course, this is assuming that you've already coded and included start_trace_log(). You should also only include this on a development server. Scripts with debug flags shouldn't make it to production.

1 Comment

Thanks for editing and reply. You are right, this feature should not be available on production system, only for development. What You described, requires me to call the log function after each line and does not automatically write a full trace/log function on demand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.