Jump to content

shutdown function with mail error


TSA

Recommended Posts

First post here, so I hope this isn't a dumb question.

 

I want to use register_shutdown_function to have some code run whenever my script finishes to do some cleanup.  This generally works, even if there is a fatal error when I'm calling the mail function, but not if I suppress errors with the at-sign.

 

The following code

 

<?

  function Shutdown()

  {

      print "hello";

  }

 

  register_shutdown_function('Shutdown');

  set_time_limit(1); // quit timeout to ensure error

  ini_set('SMTP', '192.168.1.115'); // bad smtp address to generate errors

  print "blah";

  mail('[email protected]', 'testing', 'testing');

?>

 

does what I would expect and prints

 

blah

Warning: mail() [function.mail]: Failed to connect to mailserver at "192.168.1.115" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in [path] on line 11

 

Fatal error: Maximum execution time of 1 second exceeded in [path] on line 14

hello

 

Put if I run that same code with the at-sign in front of mail, it doesn't run the shutdown function.  I get:

 

blah

 

This doesn't make sense to me.  Obviously the error messages shouldn't be printed in the second scenario, but I would think the "hello" should be.

 

I'd greatly appreciate any clarification of why this is.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/150226-shutdown-function-with-mail-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.