Home >Backend Development >PHP Tutorial >PHP function timeout handling method_php tips
The example in this article describes how to handle PHP function timeout. Share it with everyone for your reference, the details are as follows:
register_shutdown_function
Registers the function named by function to be executed when script processing is complete or when exit() is called.
This function can be registered repeatedly and will be called sequentially. This function will be called when a fatal error or exit occurs
error_reporting(0); register_shutdown_function ( 'handleShutdown' ); function handleShutdown (){ $error = error_get_last (); // 根据错误信息,判断是否是超时了 if ( $error && strpos ( $error [ 'message' ], 'Maximum exec' )!== false ) { echo 'handle time out'; } } set_time_limit(2); sleep(3);
Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction to PHP Basic Syntax Tutorial", "Summary of PHP Error and Exception Handling Methods" and " Summary of common PHP functions and techniques》
I hope this article will be helpful to everyone in PHP programming.