In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the common interview questions in PHP". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the common interview questions in PHP.
PHP often meets with test questions.
1. Detail a complete HTTP request process
The core of this problem is domain name resolution and server (nginx) resolution, which are basically described in detail.
Step 1. Parse URL
The browser parses the current URL data to determine whether the URL is a legitimate link. If it is a legitimate link, proceed normally to the next step. If it is not a legal link, it will perform search functions, such as Baidu, 360th, Google search, etc.
Step 2: resolve the domain name
The server exists as an ip. While the domain name needs to be resolved to ip, there are three small steps to resolve IP:
1) parse the domain name data from the browser's own cache
2) resolve the domain name from the HOST file of the local computer
3) resolve the domain name through the DNS server
Step 3. Get the information
In this step, we get the URL information, mainly IP and port information.
Step 4: package and three-way handshake
The browser packages the request information and passes the data to the server through the three-way handshake of TCP.
Step 5. The server parses, processes and returns data.
The server gets the transmitted data through various levels and ways, analyzes and processes the data, and finally returns the response class MIME type data. The normal status code is 200, and the abnormal error codes are 404, 500, 501, etc.
Step 6. The browser acquires, renders and displays the data.
The browser gets the data from the server, loads the resources, renders the page and so on, and presents the page to the user.
2. What is the difference between SESSION and COOKIE? please explain the cause and effect of the agreement?
1) http stateless protocol cannot tell whether a user is from the same website, and different pages requested by the same user cannot be regarded as the same user.
2) SESSION is stored on the server side and COOKIE on the client side. Session is relatively secure. Cookie can be modified by some means, but it is not secure. Session relies on cookie for delivery.
When cookie is disabled, session cannot be used properly. The disadvantage of Session: it is saved on the server side, and each read is read from the server, which consumes resources on the server. Session is saved in a file or database on the server side, by default in a file, and the file path is specified by the session.save_path of the php configuration file. The Session file is public.
What is the meaning of 302,403,500 codes in 3.HTTP status?
One, two, three, four, five principles: one. Message series two, success series three. Redirect series four. Request error series five. Server-side error series
302: temporary transfer succeeded, the requested content has been transferred to the new location 403: access to 500 is prohibited: server internal error 401 indicates unauthorized.
4. Create compressed package and decompress the command under Linux
Tar.gz:
Packaging: tar czf file.tar.gz file.txt
Decompress: tar xzf file.tar.gz
Bz2:
Packaging: bzip2 [- k] files
Extract: bunzip2 [- k] file
Gzip (for files only, do not keep the original files)
Packaging: gzip file1.txt
Decompress: gunzip file1.txt.gz
Zip:-r pair directory
Packaging: zip file1.zip file1.txt
Decompress: unzip file1.zip
5. Please write down the meaning of the data type (int char varchar datetime text); what is the difference between varchar and char?
Int integer char fixed length character Varchar variable length character Datetime date time type Text text type Varchar and char the difference between char is a fixed length character type, it takes up as much space as it allocates. Varchar is a variable-length character type, which takes up as much space as the content has, which can effectively save space. Because the varchar type is variable, the server does additional operations when the data length changes, so it is less efficient than the char type.
6. What is the basic difference between MyISAM and InnoDB? How to implement the index structure?
MyISAM type does not support transactions, table locks, easy to produce fragments, need to be optimized frequently, read and write faster, while InnoDB types support transactions, row locks, and crash resilience. Read and write slower than MyISAM.
Create index: alert table tablename add index (`field name`)
7. Send a cookie to the client without using cookie.
Understanding: when session_start () is turned on, a constant SID is generated, when COOKIE is turned on, the constant is empty, and when COOKIE is closed, the value of PHPSESSID is stored in this constant. Pass the value of SESSIONID by adding a SID parameter after URL, so that the client page can use the value in SESSION. When the client opens COOKIE and the server opens SESSION. The first time the browser requests, the server will send a COOKIE to the browser to store SESSIONID. When the browser requests for the second time, it will already exist
8. The difference between isset () and empty ()
Isset determines whether a variable exists. Multiple variables can be passed in. If one of the variables does not exist, false is returned. Empty determines whether the variable is empty or false. Only one variable can be passed, and true is returned if it is false.
9. How many ways are there to persist redis?
A: there are two main ways:
1) Snapshot persistence
It has been turned on automatically in the redis configuration file
The format is: save N M
It means that if redis is modified at least M times within N seconds, redis will take a snapshot to disk.
Of course, we can also manually execute save or bgsave (asynchronous) commands to take snapshots.
2) append only file AOF persistence
There are three modes, such as
Appendfsync everysec defaults to force writing to disk once per second
Appendfsync always forces it to write to disk every time it performs a write operation
Appendfsync no depends entirely on os. Performance is the best, but persistence is not guaranteed.
The third mode is the best. Redis also takes the third mode by default.
10.mysql storage engine
Answer: there are two kinds of commonly used ones, one is innodb, the other is myisam. The main difference between the two is
1) myisam does not support transaction processing, while innoDB supports transaction processing
2) myisam does not support foreign keys, while innoDB supports foreign keys
3) myisam supports full-text search, while innoDB does not support full-text search until after the MySQL5.6 version
4) the form of data storage is different. The mysiam table is stored in three files: structure, index, and data. InnoDB storage stores the structure as a file, and the index and data as a file.
5) myisam has better performance in querying and adding data than innoDB,innoDB in batch deletion.
6) myisam supports table locks, while innoDB supports row locks
What is 11.sql injection and how to prevent sql injection?
A: SQL injection attacks refer to users or hackers who build special inputs as parameters to our Web applications, and most of these inputs are combinations of SQL syntax that execute SQL statements to perform the actions desired by the attackers. The main reason is that programmers do not carefully filter the data entered by users, resulting in illegal data intrusion into the system. Therefore, we must prevent sql injection in the development process, mainly from two aspects:
1) the placeholder way is to preprocess the sql statement and then execute the sql statement
2) escape the values entered by the user through the functions addslashes or mysql_real_escape_string, and escape some special characters.
twelve。 Have you ever used pretreatment?
A: yes, there is a prepare method in the PDO class that can preprocess, and the excute method in the PDOStament class can perform preprocessing. There are two kinds of preprocessing parameters, one is the string placeholder, the other is? Placeholder,: string placeholder passes in an associative array when preprocessing passing parameters, and? The placeholder passes an indexed array. The two cannot be mixed, but it is generally recommended: string placeholders.
13. Do you still use your own processing with the framework?
A: data security is generally taken into account in mature open source frameworks, but sometimes when we use some native SQL statements, we need to consider our own preprocessing of sql statements. Of course, sometimes we don't want to use filtering methods in the framework, such as when using a text editor, we can use our own filtering methods.
How is 14.mysql optimization done?
A: mysql optimization is mainly realized from the following aspects:
1) Design perspective: storage engine selection, field type selection, paradigm
2) functional perspective: you can take advantage of mysql's own features, such as indexing, query caching, defragmentation, partitioning, table partitioning, etc.
3) the optimization of sql statement: simplify the query statement as much as possible, query as few fields as possible, optimize paging statement, grouping statement and so on.
4) deploy the heavy load architecture: the database server comes out separately, and when the load is heavy, the master-slave replication and read-write separation mechanism can be used to design.
5) upgrade the database server from hardware.
15. Please explain the difference between passing values and passing references in PHP. When to transmit the value and when to pass the quote?
Pass by value: any change to the value within the function range is ignored outside the function
Pass by reference: any change to the value within the scope of the function can also reflect these changes outside the function
Pros and cons: when passing by value, php must copy the value. This can be a costly operation, especially for large strings and objects. Passing by reference does not require copying values, which is good for performance improvement.
16. What is the function of error_reporting in PHP?
Sets the error level of PHP and returns to the current level.
17. Using PHP to describe the quick sort algorithm, can the object be an array?
Principle: quick sorting uses divide-and-conquer strategy to divide the data sequence to be sorted into two subsequences. the specific steps are as follows:
(1) pick an element from a series and call it a "benchmark".
(2) scan the series once, putting all the elements smaller than the "base" in front of the base, and all the elements larger than the "base" after the base.
(3) through recursion, each subsequence is divided into smaller sequences until the subseries of elements less than the reference value and the subsequence of elements greater than the reference value are sorted.
/ / Quick sort (array sort) function QuickSort ($arr) {$num = count ($arr); $lumped _ blank _ 0; for ($item1 / new_arr / 1) {$left = QuickSort ($left);} $new_arr = $left; $new_arr [] = $arr [0]; if ($r > 1) {$right = QuickSort ($right);} for ($itransitive / ihandleblank null; $this- > getcon ($host,$username,$password,$dbname);} public static function getBb () {self::$instance=new Db (); return self::$instance } private function getcon ($host,$username,$password,$dbname) {if ($this- > handlewritten null) {return true;} $this- > handle=mysqli_connect ($host,$username,$password,$dbname);}} where does the 22.PHP session extension store session data by default? D
A) SQLite Database
B) MySQL Database
C) Shared Memory
D) File System
E) Session Server
The strtolower () and strtoupper () functions of 23.PHP may cause Chinese characters to be converted into garbled codes on servers installed with non-Chinese systems. Please write two alternative functions to achieve string case conversion compatible with Unicode characters.
A: the reason is that Chinese is made up of many bytes, while only a single English character in the English system has only one byte, so every byte in Chinese is processed by strtolower (), and the changed Chinese bytes are spliced together into garbled code (the character corresponding to the newly generated code mapping may not be Chinese).
Manual solution: use str_split (string string,intstring,intsplit_length = 1) to cut each byte, like Chinese can be cut into three bytes. Convert the identified bytes if they are English letters.
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.