本文實(shí)例講述了PHP函數(shù)超時(shí)處理方法。分享給大家供大家參考,具體如下:
register_shutdown_function
Registers the function named by function to be executed when script processing is complete or when exit() is called.
此函數(shù)可以重復(fù)注冊(cè),然后會(huì)依次調(diào)用 當(dāng)發(fā)生致命性錯(cuò)誤或者exit時(shí)都會(huì)調(diào)用此函數(shù)
error_reporting(0);register_shutdown_function ( 'handleShutdown' );function handleShutdown (){ $error = error_get_last (); // 根據(jù)錯(cuò)誤信息,判斷是否是超時(shí)了 if ( $error && strpos ( $error [ 'message' ], 'Maximum exec' )!== false ) { echo 'handle time out'; }}set_time_limit(2);sleep(3); 
















