Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trace code execution in PHP?

Tags:

I would like to see a log of THE WHOLE code execution of PHP script(s). Something like this: http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Tracer (for lack of better example; no flame please).

Is there some way how to obtain the log in PHP?

Note: I know I can use a debugger but that's not the same.

like image 276
Martin Vseticka Avatar asked Jan 15 '13 16:01

Martin Vseticka


People also ask

How can I trace PHP code?

In any function you can see the whole backtrace by using debug_backtrace(...) Or you can use Xdebug profiler to profile your PHP scripts. debug_backtrace is put on a specific place in a PHP script but I want to see a log of whole code execution - from start to the end.

Where is PHP code is executed?

PHP code is executed on the server.

What is stack trace in PHP?

But, what is a stack trace? In essence, it is a rundown of every file and function that is called leading up to the error. To be clear, a stack trace doesn't include the files and functions that are touched before the error occurred, only the chain of methods that are called as the error happened.

How is PHP code executed?

Until version 3, PHP source code was parsed and executed right away by the PHP interpreter. PHP 4 introduced the the Zend engine. This engine splits the processing of PHP code into several phases. The first phase parses PHP source code and generates a binary representation of the PHP code known as Zend opcodes.


1 Answers

Xdebug is definitely what you want, but with something like callgrind from the valgrind suite as well.

Zend blog post here should give you some pointers: http://devzone.zend.com/1139/profiling-php-applications-with-xdebug/

like image 52
BenLanc Avatar answered Oct 04 '22 16:10

BenLanc