PHP’s register_shutdown_function

Written on March 20, 2008 | by vinu |

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

Bookmark and share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • StumbleUpon
  • BlinkList
  • blogmarks
  • Furl
  • Slashdot
  • Spurl
  • Technorati
  • YahooMyWeb
  • description
  • e-mail
  • Facebook
  • Google
  • IndianPad
  • Live
  • Ma.gnolia
  • NewsVine
  • Reddit
  • TwitThis

Post a Comment

About Me

Here's my blog on stuff I keep finding on the Web. More

Want to subscribe?

 Subscribe in a reader Or, subscribe via email:
Enter your email address:  
On the Go? Get this on your Widsets: Add to my Widsets
Find entries :