PHP error handling

Thank you all in advance.

I am currently working on tweaking / improving the MVC framework that I wrote from scratch for my company. It is relatively new, so it is certainly incomplete. I need to include error handling in the structure (everything should have access to error handling), and it should be able to handle various types and levels of errors (user errors and Framework errors). My question is the best way and the best mechanism for this? I know how to handle the PHP 5 exception and the PEAR error mechanism, but I never used them. I need something effective and easy to use.

Would it be better to create my own error handling or use something already done? Any suggestions, tips, questions are certainly welcome. Ultimately, I would have thought it was sweet to somehow register an error handler with PHP, so that I just needed to throw an error and then decide what to do with it and whether to continue.

EDIT: Sorry, I have to provide more details on what errors I wanted to register. I am looking for 2 main types of errors for registration: User and Framework.

For custom errors, I mean things like bad URLs (404), illegal access to restricted pages, etc. I know that I can simply redirect to the home page or just release the JavaScript dialog box, but I want to be able to gracefully handle these errors and add more user errors as they become obvious.

As a result of Framework errors, I mean things like the inability to connect to the database, someone deleted the database table about the accident or deleted the file somehow, etc.

In addition, I will take care of developing and managing a live server.

+5
source share
4 answers

, - PHP, , , .

: set_error_handler() set_exception_handler ( ).

" " , , .

  • trigger_error() throw new Exception , , trigger_error() .
  • , dev ( ?) ( ?)
  • ""
+5

, :

  • .
  • php, : . , , .
  • , , . try-catch , .
  • error_handeling(E_ALL | E_STRICT)
  • PHP set_error_handler() . , .
  • , . .
  • , : , , .
+5

, , .

try catch, , - ( ), , , . , , .

Particletree PHP , . - . , , , , , , . , - SOAP, , .

, , , , -, sql - .

Particletree : http://particletree.com/features/php-quick-profiler/

+2

, , ( Plesk) php.

, , . , : datetime, ip , , URL- , / .

I use to force it to write a log file, but I find that it is unsafe because the directory must have a chmod of 777 and is inefficient because I had to access the latest logs every time. By sending them to me by e-mail, I immediately solve the problem.

0
source

All Articles