In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the summary of the error mechanism of PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Special note: the PHP version of the article uses 5.5.32
Error level of PHP
First of all, you need to know what is wrong with php. Up to php5.5, there are 16 error levels.
Note: be sure to open error_log when trying the following code:
Error_reporting (E_ALL); ini_set ('display_errors',' On')
E_ERROR
This error is fatal and will display Fatal Error on the page. When this error occurs, the program cannot continue to execute.
Example of error:
/ Fatal error: Call to undefined function hpinfo () in / tmp/php/index.php on line 5 hpinfo (); / / E_ERROR
Note that this level is also triggered if there is an exception that has not been caught.
/ / Fatal error: Uncaught exception' Exception' with message 'test exception' in / tmp/php/index.php:5 Stack trace: # 0 {main} thrown in / tmp/php/index.php on line 5 throw new Exception ("test exception")
E_WARNING
This error is just a warning, does not terminate the script, and the program continues with the error message Warning. Such as include, a file that does not exist.
/ / Warning: include (a.php): failed to open stream: No such file or directory in / tmp/php/index.php on line 7 / / Warning: include (): Failed opening 'a.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in / tmp/php/index.php on line 7 include ("a.php"); / / E_WARNING
E_NOTICE
The degree of error is more minor, suggesting that you should not write this way in this place. This is also a run-time error, and the wrong code may be fine elsewhere, only in the current context.
For example, the $b variable does not exist, so we assign it to another variable.
/ / Notice: Undefined variable: B in / tmp/php/index.php on line 9$ a = $b; / / E_NOTICE
E_PARSE
This error occurs at compile time. Syntax errors are found at compile time and cannot be parsed.
For example, z below is not set as a variable.
/ / Parse error: syntax error, unexpected'='in / tmp/php/index.php on line 20 zonal 1; / / E_PARSE
E_STRICT
This error was introduced after PHP5, and your code can be run, but not as suggested by PHP.
For example, pass the + + symbol in the function parameter.
/ Strict Standards: Only variables should be passed by reference in / tmp/php/index.php on line 17 function change (& $var) {$var + = 10;} $var = 1; change (+ + $var); / / E_STRICT
E_RECOVERABLE_ERROR
This level is actually ERROR-level, but it is expected to be captured, and if it is not caught by error handling, the performance is the same as E_ERROR.
It often occurs when the parameter defines the type, but the wrong type is passed in when it is called. Its error alert is also preceded by the word Catachable in front of E_ERROR 's fatal error.
/ Catchable fatal error: Argument 1 passed to testCall () must be an instance of A, instance of B given, called in / tmp/php/index.php on line 37 and defined in / tmp/php/index.php on line 33 class A {} class B {} function testCall (A $a) {} $b = new B (); testCall ($b)
E_DEPRECATED
This error indicates that you are using an old version of the function, which may be disabled or unmaintained in a later version.
For example, curl's CURLOPT_POSTFIELDS uses @ FILENAME to upload files.
/ / Deprecated: curl_setopt (): The usage of the @ filename API for file uploading is deprecated. Please use the CURLFile class instead in / tmp/php/index.php on line 42$ ch = curl_init ("http://www.remotesite.com/upload.php"); curl_setopt ($ch, CURLOPT_POSTFIELDS, array ('fileupload' = >' @'. "test"))
E_CORE_ERROR, E_CORE_WARNING
These two errors are generated by PHP's engine and occur during PHP initialization.
E_COMPILE_ERROR, E_COMPILE_WARNING
These two errors are generated by the PHP engine and occur during compilation.
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_USER_DEPRECATED
These errors are made by the user, and with trigger_error, this is equivalent to an opening to send out various types of errors to the user. This is a good way to escape try catch exceptions.
Trigger_error ("Cannot divide by zero", E_USER_ERROR); / / E_USER_ERROR / / E_USER_WARING / / E_USER_NOTICE / / E_USER_DEPRECATED
E_ALL
All errors and warnings for E_STRICT outbound.
Error control
There are many configurations and parameters in php that can control errors, as well as error log display. * * step, what we need to know is what are the wrong configurations in php?
According to php+php-fpm 's model, what will affect the php error display is that there are actually two configuration files, one is the configuration file php.ini of php itself, and the other is the configuration file of php-fpm, php-fpm.conf.
Configuration in php.ini
Error_reporting = E_ALL / / report error level, what level of error_log = / tmp/php_errors.log / / php error display log location display_errors = On / / whether the error is displayed on the output, this output may be a page, or stdout display_startup_errors = On / / whether the error message of the startup process is displayed on the page Remember that there are several Core type errors that occur at startup, which controls whether these errors display the page or not. Log_errors = On / / whether to record the error log log_errors_max_len = 1024 / / the length of the error log ignore_repeated_errors = Off / / whether to ignore the duplicate error track_errors = Off / / whether to use the global variable $php_errormsg to record * * an error xmlrpc_errors = 0 / / whether to record the error xmlrpc_error in the error message format of XML-RPC _ number = 0 / / is used as the value of the XML-RPC faultCode element. Html_errors = On / / whether to change the functions and other information in the output into HTML links docref_root = http://manual/en/ if html_errors is turned on, what is the root path of the link fastcgi.logging = 0 / / whether to throw php errors into the fastcgi
We are often asked, what is the difference between error_reporting and display_errors? These two functions are completely different.
PHP defaults to log and standard output (in the case of fpm mode standard output is the page)
The parameter to error_reporting is the error level. Indicates what level should trigger the error. If we tell PHP that all error levels do not need to trigger an error, then neither the log nor the page will show the error, which means nothing has happened.
Display_errors controls whether to display error messages in standard output
Log_errors controls whether to record error messages in the log.
Error_log is the location where the error log is displayed, which is often overridden in php-fpm, so it is often found that the error logs of cli and fpm are not in the same file.
The ignore_repeated_errors flag controls that if there is a duplicate log, only one entry will be recorded, such as the following program:
Error_reporting (E_ALL); ini_set ('ignore_repeated_errors', 1); ini_set (' ignore_repeated_source', 1); $a = $c; $a = $c; / / E_NOTICE / / Notice: Undefined variable: C in / tmp/php/index.php on line 20
There would have been two NOTICE, but now, there will only be one.
When track_errors is enabled, an error message is stored in a variable, which may be useful for logging. But I think it's really useless.
Html_errors and docref_root are very user-friendly configurations. After configuring these two parameters, the error messages we return will become linked if there is some information in the document.
Error_reporting (E_ALL); ini_set ('html_errors', 1); ini_set (' docref_root', "https://secure.php.net/manual/zh/"); include (" a2.php "); / / E_WARNING
It allows you to quickly locate where we went wrong. Isn't it very human?
Configuration in php-fpm
Error_log = / var/log/php-fpm/error.log / / php-fpm own log log_level = notice / / php-fpm own logging level php_ logging [display _ errors] = off / / overrides a configuration variable in php.ini Can be overridden by ini_set in the program php_ value [display _ errors] = off / / same as php_flag php_admin_ value [error _ log] = / tmp/www-error.log / / override a configuration variable in php.ini Cannot be overwritten by ini_set in the program php_admin_ records [log _ errors] = on / / same as php_admin_value catch_workers_output = yes / / whether to crawl the output of fpmworker request_slowlog_timeout = 0 / / slow log duration slowlog = / var/log/php-fpm/www-slow.log / / slow log record
There is also an error_log configuration in the configuration of php-fpm, which is often confused with the error_log configuration in php.ini. But what they record is different. Php-fpm 's error_log only records the log of php-fpm itself, such as fpm startup and shutdown.
The error_log in php.ini records the error log of the php program itself.
To override the error_log configuration in php.ini in php-fpm, you need to use the following functions:
Php_flag
Php_value
Php_admin_flag
Php_admin_value
The two functions of these four functions admin indicate that after the variable is set, you cannot use ini_set to reassign the variable in the code. On the other hand, php_flag/value still follows the ini_set in the php code.
Slowlog is recorded by fpm, and you can use the request_slowlog_timeout setting to determine the duration of slow logs.
This is the end of the summary of the error mechanism of PHP. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.