The specific application of register_shutdown_function function in php (including detailed explanation)

烟雨青岚
Release: 2023-04-08 19:36:02
forward
2410 people have browsed it

The specific application of register_shutdown_function function in php (including detailed explanation)

Application of register_shutdown_function in php (including detailed explanation)

In some cases, we need to execute the program At the end, do some follow-up processing work. At this time, PHP's register_shutdown_function function can help us implement this function.

1 Introduction to the register_shutdown_function function

When the PHP program is executed, the register_shutdown_function function is automatically executed. This function requires a parameter to specify who handles these functions. follow-up work. Among them, the program execution is completed, which is divided into the following situations:

⑴ An error occurs during the execution of the php code

⑵ The php code is executed successfully

⑶ PHP code running timeout

⑷ The page was forced to stop by the user

2 Steps to use the register_shutdown_function function

The use of the register_shutdown_function function is very simple and only requires 2 steps at most.

1. Customize a php class with the name CustomHandle.php, as follows:

', $message);
header('Location:http://'.$_SERVER['HTTP_HOST'].'/error.php');
exit;
}else{
//此处处理其它一些业务逻辑
}
}
}
Copy after login

2. Introduce the registration function

Introduce the CustomHandle.php file at the program entrance, and at the same time, register the register_shutdown_function function, as follows:

require 'CustomHandle.php';
register_shutdown_function(array('com\antp\CustomHandle','systemError'));
Copy after login

At this time, regardless of whether your php code is executed successfully or not, it will eventually be in the CustomHandle class systemError method.

————————————————

Copyright statement: This article is an original article by CSDN blogger "Uncle Muyu" and follows CC 4.0 BY-SA Copyright agreement, please attach the original source link and this statement when reprinting.

Original link: https://blog.csdn.net/tdcqfyl/article/details/52291237

Recommended tutorial: "PHP Tutorial

The above is the detailed content of The specific application of register_shutdown_function function in php (including detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!