Determine where PHP exits using code, not debugger

I can not understand where the application comes out. I would prefer not to worry about the debugger, and adding declare(ticks=1); it would be painful for each file (I'm not in the mood to work with sed). A similar question has been asked, but not with these limitations.

How can I find out where the code is?

Clarification:

While this question is similar to the Fastest way to determine where a PHP script comes out , I would like to find a solution that works without a debugger. I know how to do this with a debugger, but I don’t always have access to such tools.

+6
source share
2 answers

You do not need to add announcements (ticks) to all your files. just one entry point is enough:

 <?php function my_tick() { echo 'tick'; } register_tick_function('my_tick'); declare (ticks=1) { include("lib.php"); echo "1"; test(); } 

and lib.php:

 <?php echo "2"; function test(){ echo "3"; } 

and since you're looking for a code-based solution, I assume your sources provide a single entry point.

+1
source

I usually use my code using a variable to register events, then decide what to do at the exit point by registering the shutdown function:

 class flightRecoder { var $data; var $err; function __constructor() { $this->data=array(); } function error($errno, $errstr, $errfile, $errline) { if ($this->err<$errno) { $this->err=$errno; } $this->note("ERROR! $errno $errstr", $errfile, $errline); } function note($note, $infile, $atline) { $this->data[]="$note in $infile at $atline"; } function finish() { if ($this->errno || rand(1,20)==19) { .... } } } $log=new flightRecorder(); register_shutdown_function(array($log, 'finish')); set_error_handler(array($log, 'error')); 

In your case, you just need to ensure that error_logging has been enabled (to catch fatal errors), and then insert a note in front of any exit statement.

+1
source

Source: https://habr.com/ru/post/951446/


All Articles