Home > headlines > body text

If you learn these PHP knowledge points well, you can also enter Baidu!

PHPz
Release: 2017-02-13 15:42:29
Original
2944 people have browsed it

Baidu’s interview, especially the first interview, is not difficult overall. The first two rounds of technical interviews require handwritten code, and the main categories involved include language foundation, design patterns, algorithm foundation, and database. The most important thing is the foundation, the foundation, the foundation. It covers a wide range of topics, but they are all things that a programmer should and should know. Answers are for reference only. (The article is taken from the Internet)

Now we have compiled 10 questions as follows:

1. What is the integer overflow problem in PHP?

2. How to understand OOP

3. Your understanding of design patterns and MVC

4. The difference between HTTP protocol 1.0 and 1.1, and briefly talk about the HTTP protocol

5. Briefly talk about the rewrite mechanism in Apache and URI routing mechanism in PHP framework

6, MySQL index mechanism, principles of using composite index

7, MySQL table types and the difference between MyISAM and InnoDB

8, Let’s briefly talk about the quick sort algorithm

9, the basic use of awk, sed, and sort (examined with examples)

10, the use and understanding of Memcached and redis

= ===============================================

【1】What is the integer overflow problem in PHP?

The word length of PHP’s integer numbers is related to the platform. For 32-bit operating systems, the largest integer type is more than two billion. , in fact, it is 2 to the 31st power, and the minimum is -2 to the 31st power. PHP does not support unsigned integers. If a number exceeds the range of integer, it will be automatically interpreted as a float. If the result of the performed operation exceeds the range of integer, float will also be returned. (What about integer overflow in Java and C)

[2] How to understand OOP

OOP, object-oriented programming, includes three aspects, inheritance and encapsulation , polymorphism, the most fundamental thing is abstraction.

Inheritance, that is, extensibility, extends the functions of existing parent classes through subclasses.

Encapsulation requires that the outside cannot access the internal data of the object at will, that is, the specific implementation in the class is encapsulated. The user does not need to know the specific internal implementation, as long as he knows what it does and how to use it. .

Polymorphism is the abstraction and interface of a class, and the ability of the same class to handle multiple types of objects.

In reality, anything we see can be regarded as an object, and then through further abstraction into classes, classes can evolve into many similar objects. To give a simple example, abstract a house we see into a ROOM class, including basic doors, windows, tables and other objects, and functions such as people's entry and exit. Now we inherit the ROOM class as Classroom, which includes doors, large windows, tables and chairs, and only a black and white and a podium where teachers and classmates can attend classes. Now we instantiate this Classroom class as Classroom_621 object, including two doors, four large windows, 30 sets of tables and chairs, and some students are taking Mao Zedong classes.

[3] Your understanding of design patterns and MVC

Model-View-Controller, model, view, controller. When you think of MVC, you will think of JAVA, because JAVA is a completely oriented An object language, MVC first appeared in Smalltalk. Its core is to separate the view from the data model, so that different programs can have different displays.

Model, that is, the functions, algorithms and data models written by programmers, which is what we call the system business logic layer.

View, that is, front-end, graphical interface. Displayed to users.

Controller, mainly responsible for request processing, forwarding and loading views.

Design patterns, to put it bluntly, are the summary and classification of code design experience. Design patterns were first used in the construction industry. Programming design patterns are described in the earliest GoF, including 23 design patterns, mainly used for Object-oriented procedural programming. Follow several design principles: opening and closing principle, single responsibility principle, Liskov substitution principle, dependency injection, interface separation, Dimit principle, preferring composition over inheritance, etc. It includes three categories: creational model, structural model and behavioral model.

[4] The difference between HTTP protocol 1.0 and 1.1, and briefly talk about the HTTP protocol

HTTP, Hypertext Transfer Protocol. It defines the communication rules between the browser and the server. The HTTP protocol is based on the TCP protocol of TCP/IP. The World Wide Web now uses the HTTP1.1 version. Its features include C/S mode, simple requests (GET/POST/HEAD), and flexibility (can transmit any type of data HTML , XML, JSON, custom, etc.), no connection (only one request is processed per connection, and the connection is disconnected from the time the request is issued until the 200 status is received), stateless.

The investigation of the HTTP protocol mainly includes knowledge points such as response message format, request message format, status code, etc.

Generally, an HTTP protocol includes three parts: start line, header, and body.

[Response message format]

HTTP/1.1 200 0K

Connectlon:close

Date: Thu, 13 Oct 2005 03:17:33 GMT

Server: Apache/2.0.54 (Unix)

Last—Nodified:Mon,22 Jun 1998 09;23;24 GMT

Content—Length:682l

Content—Type: text/html

This response message is divided into 3 parts: an initial status line (status line), a header, and an attachment containing the requested object itself. The status line has 3 fields: protocol version field, status code field, and reason phrase field.

[Request message format]

GET /somedir/page.html HTTP/1.1

Host:www.chinaitlab.com

Connection:close

User-agent:Mozilla/4.0

Accept-language:zh-cn

(Extra carriage return and line feed characters)

The request message One line is called a request line, and subsequent lines are called header lines. The request line has 3 fields: method field, URL field, and HTTP version field.

[Status code] See http://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html

1xx Message

2xx Success

3xx Redirect

4xx Request Error

5xx Server Error

[Common Status Code]

200 OK. The request was successful and the response headers or data body expected by the request will be returned with this response.

300 Multiple Choices. There are multiple options for requesting resources, such as requesting text in French, English, etc.

301 Moved Permanently. Indicates that the requested web page has been permanently moved to a new location

302 Found. Indicates the state the page returns to when making a temporary jump.

304 Not Modified. The client's cached resources are the latest, requiring the client to use the cache.

400 Bad Request. bad Request.

403 Forbidden. The request was rejected by the server.

404 Not Found. It means that the server cannot find the requested web page. A web page that does not exist on the server often returns an HTTP status code.

500 Internal Server Error.

503 Service Unavailable. The server is currently unable to serve requests, but service will be restored in due course.

504 Gateway Timeout. Similar to status 408, but the response comes from a gateway or proxy that timed out while waiting for a response from another server.

505 HTTP Version not supported. The HTTP protocol version is not supported.

[5] Briefly talk about the rewrite mechanism in Apache and the URI routing mechanism in the PHP framework

1) URL rewriting is actually to transfer the URL requested by the user through the browser to the background, apache Point the request to the real resource path according to the pre-configured rewriting rules. To put it bluntly, it is a sloppy trick, reshaping the real path and allowing users to access it. But the question is what is the use of doing so.

1. SEO. Make dynamic URLs static to satisfy the appetite of search engines.

2. Access control. For example, after rewriting the rules, it is difficult for the client to determine the type of background program.

3. URL redirection. When a website changes its domain name or adds an alias URL, it can easily point to the URL to be accessed through rules.

mod_rewrite uses regular expressions to dynamically modify the URL of incoming requests. It can map URLs to file system paths, or one URL to another. It uses an unlimited number of rules to manipulate URLs, and each rule can include an unlimited number of additional conditions. You can detect it in many ways, such as server variables, environment variables, HTTP headers, timestamps, etc.

mod_rewrite operates the entire URL path, including the path-info part. A rewrite rule can be set in http.conf or .htaccess. The path generated by a rewrite rule can include a request string, or internal subroutine processing, redirection of external requests, or penetration of internal proxies.

2) The URI routing mechanism in the PHP framework is similar to apache rewriting, generally including wildcards and regular rules. Allows users to redirect (remap) URI handlers. Set your own routing rules.

[6]MySQL’s indexing mechanism, the principles of using composite indexes

(The book "MySQL in a Simple Way" explains the use of indexes in more detail)

Generally, books will be used The table of contents in the book introduces the indexing mechanism, including that some books will have special quick search appendices, which are very similar to the index of a database.

MySQL's indexes include 4 categories: primary key index (primary key), unique index (unique), regular index (index), and full-text index (fullindex).

Show index from table_name; – View the index in the table

Show status like 'Handler_read%' – View the usage of the index

Compound index, generally follow the leftmost prefix Principle, such as table_a's three columns a b c to build a composite index

create index ind_table_a on table_a(a,b,c);

Then, only a, or a, b are used in the condition , or in cases such as a, b, c, the newly created composite index will be used.

[7]MySQL table types and the difference between MyISAM and InnoDB

MySQL common table types (i.e. storage engines)

show engines to view supported table type configurations. Common ones include: MyISAM/Innodb/Memory/Merge/NDB

Among them, MyISAM and Innodb are the two most commonly used table types, each with its own advantages. We can choose the table type that suits us according to our needs.

[MyISAM]

1) Each database storage includes 3 files: .frm (table definition), MYD (data file), MYI (index file)

2) Data files or index files can point to multiple disks

3) The default engine of Linux, win defaults to InnoDB

4) For non-transactional types, avoid the additional overhead of transactional types

5) Applicable to tables with intensive select and insert

6) MyISAM’s default lock scheduling mechanism is write priority, which can be set through LOW_PRIORITY_UPDATES

7) MyISAM type data files can be COPY in different operating systems is very important and will be more convenient during deployment.

[Innodb]

1) For transactional applications

2) Suitable for update and delete intensive operations. When executing select count(*) from table, InnoDB has to scan the entire table to calculate how many rows there are, but MyISAM only needs to simply read the number of saved rows. Note that when the count(*) statement contains a where condition, the operations of the two tables are the same. When DELETE FROM table, InnoDB will not re-create the table, but will delete it row by row.

3) Introduce row-level locks and foreign key constraints

4) InnoDB does not support FULLTEXT type index

[8] Briefly explain the quick sort algorithm

Basic idea: Divide the sequence to be sorted into two parts through one sorting, one part of which has smaller records than the other part, and then continue to quickly sort the two parts separately to achieve order.

Algorithm implementation: There are two pointers low and high, the initial values ​​are low=1, high=n, and the base value is key (usually the first one is selected), then first start from the high position and move forward. Search, find the first record smaller than key and exchange it with key, then search backward from the low position, find the first record larger than key and exchange it with the base value, repeat until low=high.

In the first sorting result, the record value before key is smaller than the record value after key.

11 25 9 3 16 2 //Select 11 as key

2 25 9 3 16 11

2 11 9 3 16 25

2 3 9 11 16 25

【9】Basic use of awk, sed, and sort (examined with examples)

[Example]: There is the following file test, please count the number of occurrences of each URL, Use a shell to achieve.

 a www.baidu.com 20:00

 b www.qq.com 19:30

 c www.baidu.com 14:00

d www.baidu.com 23:00

e www.qq.com 20:30

f www.360.com 20:30

cat test| awk -F' ' '{print $2}' |sort | uniq -c | sort -rn

【10】The use and understanding of Memcached and redis

Memcached and redis are both the same key- Value's in-memory storage system stores search results through hash tables to achieve a powerful caching mechanism. High-traffic sites such as Sina's Weibo and Taobao must use these things.

The following is an introduction excerpted from the encyclopedia. The specific practice and use will be introduced in detail later.

Memcache is a high-performance distributed memory object caching system. By maintaining a unified huge hash table in the memory, it can be used to store data in various formats, including images, videos, and files. and database search results, etc. Simply put, the data is called into the memory and then read from the memory, thus greatly improving the reading speed.

Redis is a key-value storage system. Similar to Memcached, it supports relatively more stored value types, including string (string), list (linked list), set (collection) and zset (ordered set).

Off-topic:
The whole interview process felt very nice, and the interviewers seemed to be quite casual. Not as arrogant as others said. Baidu's interviews are open-ended, and there are people nearby discussing problems and plans throughout the interview process.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template