This article shares with you the latest summary of conceptual questions for PHP interview questions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Related recommendations: "The latest summary ofPHP interview questions and application questions"
Creation type: Employees act as raw materials (prototype, factory, singleton, generator, abstract factory)
Structural type: is to knock out the assembly (adapter, bridge, flyweight, appearance, agent, combination, decoration)
Behavioral type: be ordered to install the model in the dish to prevent observation (memo, chain of responsibility , command, iterator, mediator, state, template method, visitor, observer, strategy)
Usually a project is composed of a The team develops, and everyone submits the code they have written to the version server, and the project leader manages it according to the version, which facilitates version control, improves development efficiency, and ensures that the old version can be returned when needed.
Answer: Use the htmlspecialchars() function to filter the submitted content and materialize the special symbols in the string.
If the request is index.php, after the Web Server receives this request, it will start the corresponding CGI program, here is the PHP parser. Next, the PHP parser will parse the php.ini file, initialize the execution environment, process the request, return the processed result in the format specified by CGI, exit the process, and the Web server will return the result to the browser. This is a complete Dynamic PHP web access process.
PHP can automatically manage memory and clear objects that are no longer needed. . PHP uses a reference counting garbage collection mechanism. Each object contains a reference counter. When a reference is connected to the object, the counter is incremented by 1. When reference leaves the living space or is set to NULL, the counter is decremented by 1. When an object's reference counter reaches zero, PHP releases the memory space it occupies.
Phases | Calling function | Function |
---|---|---|
Module initialization phase | php_module_startup() | Mainly performs PHP framework, Initialization operation of zend engine |
Request initialization phase | php_request_startup() | For fpm, it is read in the worker process and parsed A stage after requesting data |
Script execution stage | php_execute_script() | Parse PHP syntax and generate abstract syntax tree |
Request shutdown phase | php_request_shutdown() | Executed when the request ends |
Module shutdown phase | php_module_shutdown () | Executed when the process is closed |
FastCGI is a communication protocol between the web server (such as Nginx, Apache) and the processing program (such as PHP). It is a An application layer communication protocol. php-fpm is a blocking single-threaded model process manager in PHP FastCGI operating mode. It has a single master and multi-worker structure. The same worker process can only handle one request at a time. After PHP processes the request, it forwards the parsed result to the Web server through the FastCGI protocol, and the Web server returns it to the user.
Basic implementation
PHP-FPM is the implementation of fast-cgi, providing process management functions, including master and worker processes:
worker—Request processing
The worker process continuously accepts requests. When a request arrives, it will read and parse the data of the FastCGI protocol. After the parsing is completed, the PHP script will be executed, and the request will be closed after the execution is completed. The steps for each worker to process requests are as follows:
There is a parameter in the structure of the worker process to record the stage fpm_scoreboard_proc_s->request_stage the worker is currently in. During a request, this value will be set to the following values:
master–Process Management
master will no longer return after calling fpm_run(), but will enter an event loop. From then on, master will always revolve around Several events are processed. Before analyzing these events in detail, we first introduce the three different process management methods of Fpm. The specific mode to be used can be specified through pm in the conf configuration, such as pm=dynamic.
The master process enters the fpm_event_loop() event loop. In this method, the master will cyclically process several IO and timer events registered by the master. When an event is triggered, the specific handler will be called back for processing.
Pre-apply for a piece of memory and manage it internally in PHP. When the application applies for memory, it will apply from this part and release it first. Back to memory management. This design can avoid the additional performance consumption of the operating system caused by the application and release of small memory.
The underlying implementation of PHP array is a hash table (also called hashTable). The hash table directly accesses memory storage based on the key (Key) There is a mapping function between the key and the value of the location data structure. The hash value obtained by the mapping function can be directly indexed to the corresponding value according to the key without comparing the keyword. In an ideal situation, the hash value is not considered. Column conflicts, the hash table search efficiency is very high, the time complexity is O (1).
Concept: refers to the way that other services that the service depends on are not created by the service itself, but are passed in from the outside.
How to achieve it? Answer: Generally speaking, it is implemented using reflection.
What problems can be solved? Answer: Reduce the coupling between service modules. When writing code, you do not need to consider the specific implementation of external services. You only need to use the service based on the interface.
Concept: Object-oriented is a design method for programs, which helps improve the reusability of programs and makes the program structure clearer.
Main features: encapsulation, inheritance, polymorphism.
Five basic principles: Single responsibility principle; Open and closed principle; Replacement principle; Dependency principle; Interface separation principle.
This article first appeared on the LearnKu.com website.
Related recommendations: "2021 PHP Interview Questions Summary (Collection)"
The above is the detailed content of The latest summary of conceptual questions for PHP interview questions. For more information, please follow other related articles on the PHP Chinese website!