set_error_handler()不能捕獲致命錯誤(具體錯誤類型見手冊)。
所以需要如下方法:
<?php
ini_set ( 'max_execution_time', 1 );
function shutdown() {
$a = error_get_last ();
print_r ( $a );
}
register_shutdown_function ( 'shutdown' );
while ( true ) {
}
注意:sleep()停頓時間不算在max_execution_time中。