Question

I have the following script

<?php
      echo "I am alive<br>";
      die("I am dying<br>");
      echo ("Dead");

?>

The output that I get is

I am alive
I am dying

Is there any way (alternative/substitute of die()) using which the execution of the remaining script be continued?

EDIT :

Sorry I have got what I wanted and have voted to close the question. Please neglect the question.

Was it helpful?

Solution

If the motives behind your question lie with error handling you might want to have a look at try/catch structures in PHP.

http://php.net/manual/en/language.exceptions.php

OTHER TIPS

You can use trigger_error:

<?php
  echo "I am alive<br>";
  trigger_error("I am dying<br>");
  echo ("Dead");
?>

Output:

I am alive
Notice: I am dying in ... on line 3
Dead 

If you want to run script after result is returned to the user try this:

    while (ob_get_level () != 0) {
        ob_end_clean ();
    }

    header ("Connection: close\r\n");
    header ("Content-Encoding: none\r\n");
    ignore_user_abort (true);
    ob_start ();

    // do stuff that should be returned here

    header ("Content-Length: ".ob_get_length ());
    ob_end_flush ();
    flush ();

    // do rest here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top