Print PHP Call Stack
If you want to generate a backtrace, you are looking for debug_backtrace
and/or debug_print_backtrace
.
The first one will, for instance, get you an array like this one (quoting the manual) :
array(2) {
[0]=>
array(4) {
["file"] => string(10) "/tmp/a.php"
["line"] => int(10)
["function"] => string(6) "a_test"
["args"]=>
array(1) {
[0] => &string(6) "friend"
}
}
[1]=>
array(4) {
["file"] => string(10) "/tmp/b.php"
["line"] => int(2)
["args"] =>
array(1) {
[0] => string(10) "/tmp/a.php"
}
["function"] => string(12) "include_once"
}
}
They will apparently not flush the I/O buffer, but you can do that yourself, with flush
and/or ob_flush
.
(see the manual page of the first one to find out why the "and/or" ;-) )
debug_print_backtrace() to String for log-file
Use another function. debug_backtrace() returns an array that you can loop through, format and save:
$data = debug_backtrace();
Or use output buffering for the formatted output string:
ob_start();
debug_print_backtrace();
$data = ob_get_clean();
How can I get the call stack from a Fatal Error?
I would recommend installing Xdebug on your development server. It's a very valuable tool in cases like these.
Related Topics
Fix Malformed Xml in PHP Before Processing Using Domdocument Functions
PHP Messing with HTML Charset Encoding
How to Easily Consume a Web Service from PHP
Regular Expression to Collect Everything After the Last /
How to Get the Previous Url Using PHP
How to Check If an Integer Is Within a Range
How Get Value for Unchecked Checkbox in Checkbox Elements When Form Posted
How to Install Pdo Driver in PHP Docker Image
Php: How to Explode a String by Commas, But Not Wheres the Commas Are Within Quotes
How to Call a Model from a View
How to Write Cdata Using Simplexmlelement
How to Count Days Between Two Dates in PHP
How to Call Codeigniter Controller Function from View
Populate Another Select Dropdown from Database Based on Dropdown Selection
How to Bind Parameters to a Raw Db Query in Laravel That's Used on a Model
Php. How to Use Array_Column with an Array of Objects