VT’s Tech Blog RSS

Advertisement

PHP’s register_shutdown_function

  • Did you know what the function register_shutdown_function does in PHP? The manual defines this function as :

    Registers the function named by function to be executed when script processing is complete.

    This function runs at the end of any script execution – it also runs if your script exits prematurely due to some errors. This is a useful function to catch such exceptions in your script. Eirik Hoem’s written an article on this function over at his blog, where he shows an example on how to trap a premature end of script due to a fatal error:
    <?php
    $clean = false;
    function shutdown_func(){
    global $clean;
    if (!$clean){
    die("not a clean shutdown");
    }
    }
    register_shutdown_function("shutdown_func");
    $a = 1;
    $a = new FooClass(); // will fail with fatal
    $clean = true;
    ?>

    Read Eric’s Article at : Dying with grace – PHP’s register_shutdown_function

    • Share/Save/Bookmark

Advertisement

blog comments powered by Disqus