一、前言
對於一些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);