


The latest summary of conceptual questions for PHP interview questions
Apr 07, 2021 am 09:39 AMThis 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

Undress AI Tool
Undress images for free

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

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

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)

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

Select the appropriate AI voice recognition service and integrate PHPSDK; 2. Use PHP to call ffmpeg to convert recordings into API-required formats (such as wav); 3. Upload files to cloud storage and call API asynchronous recognition; 4. Analyze JSON results and organize text using NLP technology; 5. Generate Word or Markdown documents to complete the automation of meeting records. The entire process needs to ensure data encryption, access control and compliance to ensure privacy and security.
