register_shutdown_function Register a function for execution on shutdown


register_shutdown_function

(PHP 4, PHP 5)

register_shutdown_functionRegister a function for execution on shutdown

说明

void register_shutdown_function ( callback $callback [, mixed $parameter [, mixed $... ]] )

Registers a callback to be executed after script execution finishes or exit() is called.

Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as they were registered. If you call exit() within one registered shutdown function, processing will stop completely and no other registered shutdown functions will be called.

参数

callback

The shutdown callback to register.

The shutdown callbacks are executed as the part of the request, so it's possible to send output from them and access output buffers.

parameter

It is possible to pass parameters to the shutdown function by passing additional parameters.

...

返回值

没有返回值。

错误/异常

If the passed callback is not callable a E_WARNING level error will be generated.

更新日志

版本 说明
4.1.0 The shutdown functions are now called as a part of the request. In earlier versions under Apache, the registered shutdown functions were called after the request has been completed (including sending any output buffers), so it was not possible to send output to the browser using echo() or print(), or retrieve the contents of any output buffers using ob_get_contents(). Headers were also always already sent.

范例

Example #1 register_shutdown_function() example

<?php
function shutdown()
{
    
// This is our shutdown function, in 
    // here we can do any last operations
    // before the script is complete.

    
echo 'Script executed with success'PHP_EOL;
}

register_shutdown_function('shutdown');
?>

注释

Note:

Working directory of the script can change inside the shutdown function under some web servers, e.g. Apache.

参见

  • auto_append_file
  • exit() - Output a message and terminate the current script
  • The section on connection handling


«  recode_string
» register_tick_function
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3