开发者

What can I do to make my PHP web application fail in a more noisy way?

What can I do to make my PHP web application fail in a more noisy way?

I am using an MVC pattern and often whe开发者_Python百科n classes fail to load or failures they do so without error.


<?php
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
ini_set( 'log_errors', '1' );

function error_handler($errno, $errstr, $errfile, $errline) {
  system('/usr/bin/mplayer /home/user/music/Moras_Modern_Rhythmists/Mr._Ghost_Goes_to_Town.mp3', $retval);
  return true;
}

set_error_handler( "error_handler" );
?>


Depending on what your error reporting level is at, you could try raising it via .htaccess.

php_value display_errors 1
php_value error_reporting 2147483647 


Use the require_once method to load your files instead of include.

I think that's what you're asking, right?


If you're doing testing, check whether your php.ini settings has display_errors property turned on.


<?  ini_set("Melodramatic", "true"); ?>


The easy answer: die('A fatal error occurred')

In a PHP application I wrote, I came up with a convention of using a variable or class member named $err_msg which is initially set to null . When an error happens, set it to a human readable string. When it's time to check errors, check $err_msg and put it on display for the end-user. If it's an AJAX call, echo $err_msg on failure, echo 'OK' on success.

In my case, I wrote a simple jQuery-based status box that can display busy indicators and errors. When an AJAX call returns an error message, I make the status box fade in with a red background and display the error message. It's quite nice and uniform.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜