开发者

alternative of `die()` in php [closed]

开发者 https://www.devze.com 2022-12-31 15:54 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 12 years ago.

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.


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消