本文實例講述了PHP函數超時處理方法。分享給大家供大家參考,具體如下:
register_shutdown_function
Registers the function named by function to be executed when script processing is complete or when exit() is called.
此函數可以重復注冊,然后會依次調用 當發生致命性錯誤或者exit時都會調用此函數
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);