This article to share the content is the analysis of PHP error handling, automatic loading, stack heap memory and operating mode, has a certain reference value, the need for friends can refer to
Php Error Handling
Php Error Level :
E_error fatal error, the script will be terminated. Value is 1
E_warning warning Error, giving prompt, not terminating run value of 2
E_parse syntax parsing errors at compile time, parsing errors are only generated by the parser. Value of 4
E_notice Runtime notification error, indicating that the script may encounter an error when the value is 8
E_core_error A fatal error occurred during PHP initialization startup. This error is similar to E_error, but is generated by the core of the PHP engine. Value of 16
e_core_warning PHP Initialization Warning (non-fatal error) occurred during startup. Similar to e_warning, but generated by the core of the PHP engine. Value of 32
E_compile_error Fatal compile-time error. Similar to E_error, but generated by the Zend scripting engine. Value of 64
E_compile_warning Compile-time warning (non-fatal error). Similar to e_warning, but generated by the Zend scripting engine. Value of 128
E_user_error user-generated error messages. Similar to E_error, but is generated by the user himself using the PHP function Trigger_error () in the code. Value of 256
E_user_warning user-generated warning messages. Similar to e_warning, but is generated by the user himself using the PHP function Trigger_error () in the code. Value of 512
E_user_notice user-generated notification information. Similar to E_notice, but is generated by the user himself using the PHP function Trigger_error () in the code. Value of 1024
E_strict enables PHP to modify the code recommendations to ensure the best interoperability and forward compatibility of the code. Value of 2048
E_recoverable_error can be captured by a fatal error. It indicates that a potentially very dangerous error has occurred, but has not yet caused the PHP engine to be in an unstable state. If the error is not captured by the user custom handle (see Set_error_handler ()), it becomes a e_error and the script terminates. Value of 4096
E_deprecated run-time notifications. When enabled, warns you about code that might not work correctly in a future release. Value of 8192
E_user_deprecated a warning message that the user is producing less. Similar to e_deprecated, but is generated by the user himself using the PHP function Trigger_error () in the code. Value of 16384
E_all represents all error and warning messages except for e_strict. Value of 30719
Using bitwise operators to display or mask errors (binary permission judgment)
Php There is a configuration about the error
error_reporting set the level of error reporting , level settings can be seen above
The default value is E_all & ~e_notice, which indicates that all errors except E_notice and e_strict are displayed
E_strict error levels are not included in E_all, you must explicitly enable this level to appear
It makes no sense to use error level constants outside of PHP, which can be replaced with decimal digits, such as 2147483647 containing all errors
display_errors whether to output errors to the screen
Although it is possible to reset using Ini_set, it cannot be set when a fatal error occurs in PHP
display_startup_errors whether to display error at startup
log_errors whether to log error messages from the script to Log
Log_errors_max_len
Sets the maximum number of bytes for the log_errors. The error_log will add information about the source of the error. The default value is 1024, and if set to 0 indicates an unlimited length. This length sets the error to the record, the error that is displayed, and the $php _errormsg will have a limiting effect.
Ignore_repeated_errors
Do not log duplicate error messages,
Ignore_repeated_source
When a duplicate message is ignored, the source of the message is also ignored. When this setting is turned on, the duplicate information will not be recorded by different files or different source code lines.
Report_memleaks
If this parameter is set to OFF, the memory leak information is not displayed (in stdout or in the log). This is the send to stderr on Posix platforms. On Windows, it'll be send to the debugger using OutputDebugString (), and can is viewed with tools Like»dbgview. This is only valid for debug compilation and requires that error_reporting contain e_warning to work
Track_errors
If turned on, the last error will always exist in the variable $php _errormsg.
Html_errors
Close the HTML tag in the error message. This new HTML format error message is clickable, which directs the user to the reference page of the function that describes the error or causes the error to occur. These references are related to the settings of Docref_root and Docref_ext.
Error_prepend_string string
The contents of the output before the error message.
Error_append_string string
The contents of the output after the error message.
Error_log
Sets the file to which the script error will be logged. The file must be writable by the Web server user. If the special value syslog is set, the error message is sent to the system logger. On UNIX and similar systems, syslog (3) is used, and the event log is on the Windows NT class system. System logging is not supported on Windows 95. See also: Syslog (). If the configuration is not set, the error message is sent to the SAPI error logger. For example, it appears in the Apache error log, or it is sent to stderr in the CLI.
Error handling related methods and usage personal understanding
Debug_backtrace-generates a backtracking trace (BackTrace) to set the number of stacks returned by the parameter limit,
You can find out the stack information that invokes the function, which is helpful for error checking, similar to the debug TP
Debug_print_backtrace (); Direct print backtracking, similar to Debug_backtrace,
error_clear_last-Clear Last Error
error_get_last-get the last error that occurred
error_log-send an error message to a place where the error can be stored in a file, but the error message cannot have NULL
error_reporting-set what PHP errors should be reported, as with PHP.ini
restore_error_handler-the error handling function before the restore,
restore_exception_handler-restores the exception handler that was previously defined.
set_error_handler-set user-defined error handlers that need to be defined before the error
The following level of errors cannot be handled by user-defined functions: E_error, E_parse, E_core_error, e_core_warning, E_compile_error, e_compile_warning, and in call set_ Most e_strict generated in the file where the Error_Handler () function is located.
Just as the Error_reporting INI setting controls the display of errors, the 2nd parameter can be used to mask the triggering of Error_Handler. Without the mask, regardless of how error_reporting is set, Error_Handler is called every time the error occurs.
set_exception_handler-setting user-defined exception handling functions
trigger_error-generates a user-level error/warning/notice information
Aliases for User_error-trigger_error
Register_shutdown_function the registration function that executes after PHP terminates the script, the first parameter supports the function, and a statement that contains the instantiated class, an array of class methods (the class is instantiated at the time of registration);(as long as the registration succeeds, what errors can be captured)
Php Auto Load
Personal Insights
The main difference between Spl_autoload_register and __autoload is that
__autoload is just a function that can only be defined in PHP once, if you want to load the plug-in and so on, need constant if else judgment, or composer, will be very troublesome
Spl_autoload_register can customize various processing functions according to the folder, or plug-in, create an automatically loaded queue, will continue to search according to the queue, until the queue is complete or return True (the file found by default returns True)
Stack Memory ( Personal Understanding )
Heap: Storing user-defined variables
Stacks: Some of the basic type variables defined in the function, the reference variables of the object, are all in the stack space and will be freed automatically when the scope is exceeded
Information supplement:
Heap :
When a variable defined in a file is modified by static, it is changed to the global data area without consuming stack memory
Stack :
Stack memory is generally stored in the function of the call information and variables declared in the function, because the function of the call is recursive, the outer function must be called by the inner layer of the function is loaded and executed, and must wait until the inner layer is called function end before the end, this advanced mechanism is why called stack memory reason.
PS: At compile time, the compiler collects all the defined variables in this function and puts them in front of the function to request memory, so the order in which they go in and out of the stack is not the order you define when you write the program, but the function executes the forward stack and the function executes after the execution is done.
other :
Const,global,static is stored in the global data area after decoration.
Super global variables, global variables, are static variables, stored in the global data area
Less information, waiting to be corrected and perfected
Phpweb operating mode
Php operating mode :
1) CGI (Universal Gateway Interface/Common Gateway Interface)
Generally executable programs, such as EXE files, and Web servers each occupy a different process, and generally a CGI program can only handle one user request. In this way, when the user requests a very large amount of resources, such as memory, CPU time, and so on, resulting in low performance.
2.FastCGI (resident type cgi/long-live CGI)
FastCGI is an upgraded version of CGI, fastcgi like a resident (long-live) type of CGI, it can be executed all the time, as long as the activation, not each time will have to spend to Fork once (this is the most criticized by CGI Fork-and-execute mode).
FastCGI is a scalable, high-speed interface for communicating between HTTP server and dynamic scripting languages. Most popular HTTP servers support FASTCGI, including Apache, Nginx, and lighttpd, while FASTCGI is supported by a number of scripting languages, including PHP.
FastCGI interface mode uses the C/s structure, can separate the HTTP server and the script parsing server, and start one or more script parsing daemon on the script parsing server. Each time the HTTP server encounters a dynamic program, it can be delivered directly to the fastcgi process to execute, and the resulting results are returned to the browser. This approach allows the HTTP server to handle static requests exclusively or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.
PHP-FPM is the fastcgi manager that comes with PHP
3) CLI (command line run/Interface)
4.Web Module mode (the mode of Web server operation such as Apache)
This pattern is an extension of Apache based on CGI
5.ISAPI (Internet Server application program Interface) is a set of Web service-oriented API interfaces provided by Microsoft, which can implement all the functions provided by CGI and extend it on this basis. As provided by the filter application interface. Most ISAPI applications are used in the form of DLL dynamic libraries, can be executed after a user request, do not disappear immediately after processing a user request, but continue to reside in memory waiting to be processed by other user input. In addition, ISAPI DLL applications and Web servers are in the same process and are significantly more efficient than CGI.
Php2 species and Web Server Interaction :
Nginx:
User initiated the request to nginx current handshake, when Nginx received, pushed to php-fpm for processing, when PHP-FPM busy, Nginx will return 504 Getway
Apache:
Apache has 3 modes of operation, Prefork,worker,event,
Different processing processes and threads are created depending on the mode, and the Apache module is processed when the PHP is received.