PHP Print Call Function entry address (stack), convenient mode

Source: Internet
Author: User
Tags php print

Today the site appears a bug, and then directly in the database class to write the log, to see which SQL is a problem, the SQL statement to is found, but do not know where the SQL statement came from, so I would like to, if there is a way to see how this method is currently running is called by which method, And which method is called by the previous method, and so on, it is good to find the entry address. But I have thought about it before, also in the Internet to search, is not found the relevant method, today a colleague (senior) said that the Java debugging is very common, called this stack debugging, I was on the Internet search PHP stack. I found it, and then I wrote my own way.

//call the Stack function to find the source of the calling function for easy debuggingfunctionPrint_stack_trace () {$array=Debug_backtrace(); //Print_r ($array);//information is complete   unset($array[0]); foreach($array  as $row)    {       $html.=$row[' file ']. ': '.$row[' line ']. ' Line, caller: '.$row[' function ']. <p> "; }    return $html;}


I call this method inside the core query function of my database and print the result as follows:

d:\wamp\www\meilele\includes\cls_mysql.php:471 line, call method:queryd: \wamp\www\meilele\includes\cls_mysql.php : 507 lines, call method:getalld: \wamp\www\meilele\includes\lib_common.php:732 line, call method:getallcachedd: \wamp\ Www\meilele\includes\init.php:113 line, call method:load_configd: \wamp\www\meilele\index.php:4 line, call method:Include_ Once

At a glance, has been found the entrance, too tough. There's one more way to debug later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.