7

I cannot figure out where an application is exiting. I'd rather not bother with a debugger, and adding declare(ticks=1); to each file would be a pain (I'm not in the mood for dealing with sed). A similar question has been asked, but not with these constraints.

How can I figure out where the code is exiting?

Clarification:

While this question is similar to Fastest way to determine where PHP script exits, I'd 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.

9
  • possible duplicate of Fastest way to determine where PHP script exits Commented Aug 10, 2013 at 6:47
  • 1
    Thanks @jrd1; while that question certainly is relevant, I'm looking for a different sort of solution. I'll add clarification. Commented Aug 10, 2013 at 7:13
  • 1
    Out of curiosity, why don't you want to use a debugger? Commented Aug 10, 2013 at 7:14
  • @jrd1 I don't always have root access to my clients' servers. Sometimes they use shared hosting for quick development. I used Xdebug this time, but in the future, I'd like to have a code-based solution. Commented Aug 10, 2013 at 7:16
  • 1
    My advice to you is to only ever have one exit point, that solves your problem instantly. Alternatively, you can use exit($code) to specify a code the program returns, and check that. Commented Aug 10, 2013 at 7:32

2 Answers 2

1

You don't need to add declare(ticks) to all your files. one entry point would be 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 as you are looking for a code-based solution i assume your sources do provide single entry point.

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

1 Comment

This sounds plausible. It's slightly different from what I was attempting: I was including the declare statement (early), which didn't work. I'll give it a try.
1

I usually instrument my code using a variable to log events then decide what to do at the exit point by registering a 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 it would simply be a matter of ensuring that error_logging was enabled (to catch fatal errors) then injecting a note before any exit statement.

Comments

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.