


The latest summary of conceptual questions for PHP interview questions
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 of PHP interview questions and application questions"
1. HTTP status The meaning of the medium status code
- 302: The temporary transfer was successful and the requested content has been transferred to the new location.
- 401: Unauthorized.
- 403: Access Forbidden.
- 500: Server internal error
2. Passing by value and passing by reference
- Passing by value: the actual parameters are passed Values are assigned to formal parameters, and modifications to the formal parameters will not affect the values of the actual parameters.
- Pass by reference: Pass the address of the actual parameter to the formal parameter. The actual parameter and the formal parameter point to the same storage space. Modifications to the row parameters will affect the value of the actual parameter.
3. Design Pattern
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)
4. Code management
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.
5. The code will be executed to maliciously attack users.
How to prevent?Answer: Use the htmlspecialchars() function to filter the submitted content and materialize the special symbols in the string.
6. CGI, FastCGI, PHP-FPM relationship diagramIn the entire website architecture, the Web Server (such as Apache) is only the distributor of content. For example, if the client requests index.html, then the Web Server will find this file in the file system and send it to the browser. What is distributed here is static data.
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.
- Web Server:
- Generally refers to servers such as Apache, Nginx, IIS, Lighttpd, Tomcat, etc. Web Application:
- Generally refers to PHP, Java, Asp.net and other applications. CGI:
- is a protocol for data exchange between Web Server and Web Application. FastCGI:
- Same as CGI, it is a communication protocol, but it has some optimizations in efficiency than CGI. Likewise, the SCGI protocol is similar to FastCGI. PHP-CGI:
- is the interface program of PHP (Web Application) to the CGI protocol provided by Web Server. PHP-FPM:
- is an interface program for the FastCGI protocol provided by PHP (Web Application) to the Web Server. It also provides relatively intelligent task management.
7. MVCMVC is a development model, which is mainly divided into three parts:
- m(model), which is the model, is responsible for the operation of data;
- v(view), which is the view, is responsible for the display of the front desk;
- c(controller) , that is, the controller, responsible for business logic
8. PHP’s garbage collection mechanism
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.
9. Life cycle of CLI pattern
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 |
10. php-fpm operating mechanism
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:
- Master creates and monitors sockets, forks multiple worker processes, obtains worker status through shared memory, and then controls worker processes through signals
- worker freely accepts requests
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:
- Waiting for requests: The worker process is blocked in fcgi_accept_request() waiting for requests.
- Parse the request: After the fastcgi request arrives, it is received by the worker, and then starts to receive and parse the request data until the request data is completely arrived.
- Request initialization: execute php_request_startup().
- Execute PHP script.
- Close the request.
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:
- FPM_REQUEST_ACCEPTING: Waiting for the request phase.
- FPM_REQUEST_READING_HEADERS: Read fastcgi request header phase.
- FPM_REQUEST_INFO: Obtain request information phase. This phase saves the requested method, query string, request uri and other information into the fpm_scoreboard_proc_s structure of each worker process. This operation requires locking because the master process will also operate it. this structure.
- FPM_REQUEST_EXECUTING: Execute PHP script phase.
- FPM_REQUEST_END: Not used.
- FPM_REQUEST_FINISHED: Request processing completed.
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.
- Static mode (static): This method is relatively simple. At startup, the master forks out a corresponding number of worker processes according to the pm.max_children configuration, that is, the number of worker processes is fixed.
- Dynamic mode (dynamic): This mode is more commonly used. When Fpm starts, a certain number of workers will be initialized according to the pm.start_servers configuration. During operation, if the master finds that the number of idle workers is lower than the number of pm.min_spare_servers configured (indicating that there are too many requests and the workers cannot handle them), it will fork the worker process, but the total number of workers cannot exceed pm.max_children. If the master finds that the number of idle workers exceeds pm.max_spare_servers (indicating that there are too many idle workers), it will kill some workers to avoid occupying too many resources. The master uses these four values to dynamically control the number of workers.
- Ondemand mode (ondemand): This mode is very similar to traditional cgi. It does not allocate worker processes at startup. After there is a request, it notifies the master process to fork the worker process, that is, after the request comes Then fork the child process for processing. The total number of workers does not exceed pm.max_children. The worker process will not exit immediately after the processing is completed. It will exit when the idle time exceeds pm.process_idle_timeout.
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.
11. Memory allocation process
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.
12. Implementation of PHP array
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).
13. Dependency injection
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.
14. Object-oriented
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
