PHP Fatal Error 잡아내기

Development/Codes 2012/01/06 03:21

php  실행 중에 무언가 에러가 발생하면, 이를 잡아내어 처리하기 위해, set_error_handler 함수를 사용한다.
그런데 fatal error의 경우에는 이를 이용해도 잡을 수가 없다.

php 매뉴얼에 보면 아래와 같이 설명되어 있다.
http://www.php.net/manual/en/function.set-error-handler.php

The following error types cannot be handled with a user defined function: E_ERRORE_PARSEE_CORE_ERRORE_CORE_WARNING,E_COMPILE_ERRORE_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

그럼 정말 방법이 없단 말인가?

위 매뉴얼 페이지 하단에 유저들이 작성한 댓글들을 보면 이에 대한 해결책으로 register_shutdown_function 함수를 제시하고 있다.
periklis 02-Aug-2010 03:09
How to handle fatal errors in php 5.2: 

<?php 
register_shutdown_function
('shutdownFunction'); 
function 
shutDownFunction() { 
    
$error error_get_last(); 
    if (
$error['type'] == 1) { 
        
//do your stuff     
    


?>

php 실행이 종료될 때 특정 사용자 함수를 실행하게 하면서, 그때까지 에러 발생이 있었는지 여부를 조사하는 방법이다.
 
tags :
Trackback 0 : Comment 0
◀ PREV : [1] : [2] : [3] : [4] : [5] : ... [61] : NEXT ▶