php interview frequently asked interview questions

1. What are the ways of css positioning? and usage

position means "position" in English, it is mainly used to realize the positioning of elements

There are three types of positioning in CSS:

position:fixed fixed positioning

position:relatvie relative positioning

position:absolute absolute positioning

position:static No special positioning (default value).

Notice:

When using positioning attributes, be sure to use them in conjunction with the positioning coordinates!

left: Indicates how far the positioned element is from the left

right: Indicates how far the positioned element is from the right

top: Indicates how far the positioned element is from the top

bottom: Indicates how far the positioned element is from the bottom

1 fixed positioning

grammar:

position:fixed

Fixed positioning, which is positioned relative to the browser window. No matter how the page is scrolled, the displayed position of fixed positioned elements will not change!

Features:

Fixed positioned elements which break out of the standard document flow

The level of fixed positioning elements is higher than the elements in the standard document flow, so the fixed positioning elements will overwhelm the elements in the standard document flow

fixed positioned element it no longer takes up space

A fixed positioned element where it is displayed does not scroll as the browser scrolls

2 relative positioning

grammar:

position:relative;

Relative positioning It is positioned relative to the "original self"!

Features:

Relatively positioned elements that do not break away from the standard document flow

If the relative positioning element does not set the positioning coordinates, then the relative positioning element is still in its original position

After setting the positioning coordinates of the relative positioning element, it will leave a hole in its hometown

Relatively positioned elements will overwhelm elements in the standard document flow.

The positioning coordinate value of a relatively positioned element can be negative

Notice:

Relatively positioned elements will leave a hole in their hometown, so in general it is rarely used alone. Relatively positioned elements are mainly used in conjunction with "absolute positioned" elements.

3 absolute positioning

grammar:

position:absolute;

What is absolute positioning?

Absolutely positioned elements are positioned relative to "ancestor positioned elements"!

What is an ancestor positioned element?

For an absolutely positioned element, it will first check whether its parent element has set the positioning attribute

If there is a positioning attribute set, it will be positioned relative to its parent element;

But if its parent element does not set the positioning attribute, then it will check whether the upper level element of its parent element has the positioning attribute set,

If it is set, it will be positioned relative to the parent element's parent element

But if it is not set, it will continue to search one level,

If none of its ancestors have positioning attributes set, then it will be positioned relative to the "browser window"!

① When you set absolute positioning yourself: If the parent element does not set the positioning attribute, then it will be positioned relative to the body

②When you set absolute positioning yourself: If the parent element also sets the positioning attribute, then it will be positioned relative to the parent element

③When you set absolute positioning yourself: If the parent element also sets the positioning attribute, then it will be positioned relative to the parent element

2. When using JQ to send AJAX requests, what parameters do $.ajax need to configure? ? What do they represent? ?

jQuery.ajax(options)

Parameter Description:

options : There is only one parameter, which requires data in JSON format. The following properties can be set:

async : Whether it is asynchronous, true means asynchronous, false means synchronous. Default is true

cache: Whether to cache, true means caching, false means not caching, the default is true

complete : the callback function triggered when the Ajax status code is 4

contentType : request header, if it is a POST request, this parameter is application/x-www-form-urlencoded

data : The parameter passed when sending the Ajax request, the requirement is a string

dataType : expected return value type, which can be text/xml/json data type

success : the callback function triggered when the Ajax status code is 4 and the response status code is 200

type : the http request sent, it can be get or post

url : the requested url address

3. When to use synchronous requests? ? When to use asynchronous requests? ?

1. What is a synchronous request: (false)

A synchronous request means that after the current request is sent, the browser cannot do anything. It must wait for the request to complete and return the data before executing the subsequent code. manage. That is to say, when the JS code is loaded into the current AJAX, all the code in the page will stop loading, and the page will be in a state of suspended animation. After the AJAX is executed, it will continue to run other code pages to release the suspended state (that is, when ajax returns After the data, the following function2) is executed. 2. What is an asynchronous request: (true) an asynchronous request means that the browser can continue to do anything while sending the request. Ajax sending the request will not affect the loading of the page and the user's operation, which is equivalent to two lines. Each goes its own way without affecting each other. The general default value is true, asynchronous. Asynchronous requests do not affect the user's experience at all. No matter how long or short the request time is, the user is concentrating on operating other content on the page without feeling like waiting.

4. What magic methods does PHP have? ?

Magic methods include:

__construct(), the constructor of the class

__destruct(), the destructor of the class

__call(), called when an inaccessible method is called on an object

__callStatic(), called when an inaccessible method is called in a static way

__get(), called when a member variable of a class is obtained

__set(), called when setting a member variable of a class

__isset(), called when isset() or empty() is called on an inaccessible attribute

__unset(), which is called when unset() is called on an inaccessible attribute.

__sleep(), when serialize() is executed, this function will be called first

__wakeup(), when unserialize() is executed, this function will be called first

__toString(), the response method when the class is treated as a string

__invoke(), the response method when calling an object by calling a function

__set_state(), this static method will be called when calling var_export() to export the class.

__clone(), called when the object copy is complete

__autoload(), try to load undefined class

__debugInfo(), print the required debugging information

5. Briefly describe the get method and post method

① Different ways of passing parameters

The get request passes parameters at the end of the url

The post request passes parameters at the position of the request blank line

② The size of the parameter is different

get request, the maximum value of the parameter is 2kb

Theoretically, there is no limit to the post request, but in actual application, affected by the php.ini file, it is generally 2M

③ Different types of parameters

get request, only strings can be passed

Post requests can pass not only strings but also binary data

④ Different security

Relatively speaking, the security of post requests is slightly higher than that of get requests

Its request header parameters are different

6. Word function in PHP

I receiver function

M: Instantiate the base model class

D: Instantiate a custom model class

U: assemble the URL address

7. What is the difference between an abstract class and an interface? ?

1. The use of the interface is through the keyword implements. The use of abstract classes is through the keyword extends. Of course, the interface can also be inherited through the keyword extends.

2. Member variables (including class static variables) cannot be declared in the interface, but class constants can be declared. Various types of member variables can be declared in the abstract class to realize data encapsulation

3. Interfaces do not have constructors, but abstract classes can have constructors.

4. The methods in the interface are public by default, while the methods in the abstract class can be modified with private, protected, or public.

5. A class can implement multiple interfaces at the same time, but a class can only inherit from one abstract class.

Common ground: for standard use

Abstract class: it cannot be instantiated, but can only be inherited; it is declared through the keyword abstract; the abstract class must contain at least

Contains an abstract method, which has no method body and is inherently rewritten by subclasses;

Interface: declared through interface; the member constants and methods in the interface are public, and the method does not need to write the keyword public; the interface can realize multiple inheritance;

An abstract class is a class that cannot be instantiated and can only be used as a parent class of other classes. abstract class is passed keyword

abstract to declare.

Abstract classes are similar to ordinary classes in that they both contain member variables and member methods. The difference between the two is that an abstract class must contain at least one abstract method.

An abstract method has no method body, and the method is inherently rewritten by subclasses. The format of an abstract method is: abstract function abstractMethod();

The interface is declared through the interface keyword. The member constants and methods in the interface are public, and the method does not need to write the keyword public.

Methods in interfaces also have no method body. The methods in the interface are also inherently implemented by subclasses. The functions implemented by abstract classes and interfaces are very similar. The biggest difference is that interfaces can implement multiple inheritance. Choose to draw in the application

Like a class or an interface depends on the specific implementation.

Subclasses inherit abstract classes using extends, and subclasses implement interfaces using implements.

8. How to understand the namespace? ?

Prevent class and function method conflicts

Namespaces can solve the following two problems:

(1) Name conflicts between user-written code and PHP internal classes/functions/constants or third-party classes/functions/constants.

(2) Create an alias for a very long identifier to improve the readability of the code and reduce the amount of code written.

9. Which version of PHP starts to support namespaces? ?

ThinkPHP3.2

PHP supports namespaces from version 5.3.0 onwards.

10. What extensions does PHP have? ?

PDO: A lightweight consistent interface defined by PHP for accessing databases.

CURL extension

GD extension

Memcache

Mysql

11. What should I do if there is a conflict in SVN? ?

SVN role: collaborative development.

Fusion:

renew:

12. How to understand MVC? ?

MVC is a framework pattern that enforces separation of application input, processing, and output. Applications using MVC are divided into three core components: Model, View, and Controller. They each handle their own tasks.

MVC refers to a programming model in software design. In this mode, business operations, data display, and data interaction will be split into one operation

M: The representative is a specific model, the main function of which is to interact with the database

V: Representative is a specific view (view) whose main function is to interact with users

C: The representative is the specific controller (controller), whose main function is to process specific business logic

The application program completed by the model (model), view (view), and controller (controller), the model layer is responsible for providing data, and the operations related to the database are handed over to the model layer for processing, and the view layer provides an interactive interface and outputs data, while the controller layer is responsible for receiving the request, and distributes it to the corresponding model for processing, and then calls the view layer to display.

13. What fields are there in the product table? ?

Product id, product name, product number, product category id, market price, store price, product thumbnail, product thumbnail, whether it is hot sale 1 means hot sale 0 means no, whether it is recommended 1 means recommended 0 means not recommended, Whether it is hot sale 1 means new product 0 means no, adding time means whether the product is deleted 1 normal 0 deleted status, whether the product is sold 1 sold 0 off-shelf status,

14. What should I do if the attributes of the same product ID are different? ?

The attributes in the product table are stored as a set, and the attribute table

15. cookie and session

Comparing the two, there are the following differences:

1. Role position: cookie is to save user information on the client side, and session is to save user information on the server side;

2. Save content: the cookie saves a string, and the session saves an object;

3. Action time: the cookie can be stored on the client for a long time, and the session will be closed when the session ends;

4. Generally, cookies save unimportant user information, and important information is saved by session.

5. There are two types of cookies: session cookies and file cookies. When the session cookie is closed, the data disappears. The file cookie stores the data in a file and sets the expiration time. After closing the browser, if the expiration time is not reached, open the browser again, and the data still exists.

16. The realization principle of the shopping cart

There are two situations:

1. If the user is not logged in, store the data in the cookie, and if the user logs in, transfer the data in the cookie to the database.

2. After the user logs in, the data is directly stored in the database.

17. RBAC authority management

Role-Based Access Control

Five tables: two intermediate tables admin, role, rule, admin_role, role_rule

Three tables: an intermediate table

The process of controlling whether different administrators can access a method through code is permission control.

RBAC (Role-Based Access Control, role-based access control) means that users are associated with roles and permissions. Simply put, a user has several roles, and each role has several permissions. In this way, an authorization model of "user-role-permission" is constructed. In this model, there is generally a many-to-many relationship between users and roles, and between roles and permissions.

18. How to understand interface development

First download the third-party interface file,

19. How can SMS verification code prevent SMS bombing? ?

JS Client Validation Validation

Mobile phone number limits the number of text messages (counter)

(1) Add graphic verification

Malicious attackers use automated tools to call the "Dynamic SMS Acquisition" interface to send dynamic SMS. The main reason is that the attacker can automatically make a large number of calls to the interface. Using the picture verification code can effectively prevent the tool from being called automatically, that is, before the user performs the "get dynamic SMS" operation, the picture verification code will pop up, requiring the user to enter the verification code, and then the server will send the dynamic SMS to the user's mobile phone. This method can be effective Solve the SMS bombing problem.

A secure graphic verification code must meet the following protection requirements

– The generation process is safe: the picture verification code must be generated and verified on the server side; – The use process is safe: it is valid for a single time, and is subject to the user’s verification request; – The verification code itself is safe: it is not easy to be recognized by identification tools Prevent Violent Activation Success Tutorial.

Example of graphic verification:

(2) Single IP request limit

After using the picture verification code, it can prevent the attacker from effectively calling the "Dynamic SMS" function automatically; but if the attacker ignores the verification error of the picture verification code, a large number of execution requests will bring additional burden to the server and affect business use. It is recommended to limit the number of requests for a single IP per unit time on the server side. Once the number of user requests (including the number of failed requests) exceeds the set threshold, the request to the IP will be suspended for a period of time; if the situation is particularly serious, the IP can be added to the Blacklist, prohibit the access request of this IP. This measure can limit a large number of requests from one IP address, prevent attackers from attacking a large number of users through the same IP, increase the difficulty of attacks, and ensure the normal development of services.

(3) Limit the sending time

It is recommended to limit the interval for repeatedly sending dynamic SMS, that is, after a single user requests to send a dynamic SMS, the server can only make a second dynamic SMS request after a certain period of time (generally 60 seconds here). This function can further guarantee the user experience, and avoid sending spam verification SMS maliciously including manual attacks.

Complete dynamic SMS verification code usage process

20. How to upload pictures of products? ?

21. How to set the session validity period? ?

22. Synchronous callback and asynchronous callback for payment? ?

Specific synchronous callback and asynchronous callback

Synchronous callback function: realize that when the user completes the payment, he can jump to the corresponding merchant page (to ensure that the user's payment can be correctly processed after the user's payment is completed)

Asynchronous callback function: to ensure that the merchant has done a correct processing of the user's payment

23. What is the payment process of Alipay?

1. Apply for Alipay account information, and get the corresponding APPID and public key (to Alipay), private key (save by yourself)

2. Download the official document, build a demo test locally, set APPID, synchronous and asynchronous callback address, Alipay private key and other information in config.php.

3. Create a background application

4. Use the code to realize the payment function

24. What is the function of Alipay asynchronous callback? ?

Asynchronous callback function: to ensure that the merchant has done a correct processing of the user's payment

1. Ensure that synchronization is not executed, and asynchronous unilateral requests. ()

2. Solve the problem of dropped orders

3. Relatively safe

Synchronous callback function: realize that when the user completes the payment, he can jump to the corresponding merchant page (to ensure that the user's payment can be correctly processed after the user's payment is completed) (get method)

Asynchronous callback function: to ensure that the merchant has done a correct processing of the user's payment (post method)

25. Multi-dimensional attributes of commodity modules

26. Commands commonly used in Linux

Find files:

find

-name Search by file name

-group : Search according to the group to which the file belongs

-user : search according to the owner of the file

locate command, used to retrieve data

locate file name

df command: display disk information

-l : Display local disk information

-h : Display disk information in 1024

-H : Display disk information in 1000 base

-T : Display disk format information

-t : Display disk information in the specified format

cd username:enter for

cd ~ : go home

yy: copy p : paste

vim filename: view file

27. What is the status code of hppt? ?

1. 301 MovedPermanently: The requested resource has been permanently moved to a new location, and any future references to this resource should use one of the several URIs returned by this response. Permanent redirect.

2. 302 Move temporarily: The requested resource temporarily responds to the request from a different URI. Since such redirection is temporary, the client should continue to send future requests to the original address

3. 404 Not Found: The request failed, and the resource desired by the request was not found on the server. There is no information to tell the user whether the condition is temporary or permanent

4. 200 OK: The request is successful, and the desired response header or data body will be returned with this response. This status code is

Indicates a normal state.

200 (Success): The server has successfully processed the request. Typically this means the server served the requested web page 201 (Created): The request was successful and the server created a new resource 202 (Accepted): The server has accepted the request but has not processed it 203 (Non-Authorization Information): The server has successfully processed 204 (No Content): The server successfully processed the request, but returned no content 205 (Reset Content): The server successfully processed the request, but returned no content 206 (Partial Content): The server successfully processed a partial GET request 404 (Not Found): The server could not find the requested webpage 500 (Internal Server Error): The server encountered an error and could not complete the request

28、require与include

The performance of the require() statement is similar to include(), which includes and runs the specified file.

The difference is: for the include() statement, the file must be read and evaluated every time the file is executed; when an error is reported, it will not prevent the subsequent code from running; and for the require() statement, the file is only processed once ( In effect, the contents of the file replace the require() statement). This means that if the code is likely to be executed many times, it is more efficient to use require(). On the other hand, if you read from a different file each time the code is executed, or if you have a loop that iterates through a set of files, use the include() statement

incluce loaded when used

require loads at the beginning

29. How to compile the extension of PHP program in Linux system? ?

1. Find the software compressed package and decompress it

2. Compile make && make install

3. Configure php.ini

4. Restart Apache

30. Understanding of affairs

A logical set of operations, containing several components, these parts form a whole, the operations either all succeed, or all fail and return to the original state!

Before executing the SQL statement, first execute the start transaction, which starts a transaction (the starting point of the transaction), and then executes multiple SQL statements, and finally ends the transaction. Commit means submitting, that is, the multiple SQL statements in the transaction. The effects made will be persisted to the database. Or rollback, which means rolling back, that is, rolling back to the starting point of the transaction, and all previous operations are undone!

Four characteristics of transactions ( ACID)

Atomicity: All operations in a transaction are indivisible atomic units. All operations in a transaction either succeed or fail.

Consistency: After the transaction is executed, the database state is consistent with other business rules. For example, in the transfer business, regardless of whether the transaction is executed successfully or not, the sum of the balances of the two accounts involved in the transfer should remain unchanged.

Isolation: Isolation means that in concurrent operations, different transactions should be isolated so that each concurrent transaction will not interfere with each other.

Durability: Once the transaction is successfully committed, all data operations in the transaction must be persisted in the database. Even if the database crashes immediately after the transaction is committed, when the database restarts, it must be able to restore data through some mechanism .

31、

PHP gets the current time time()

Php intercepts strings: substr function

PHP finds if there is a substring in a string:

32. Five related array processing functions?

In_array: Determine whether an element exists in the array

array_reverse() reverses the elements in the array, and the return value is the array after the reverse.

array_splice(array1,start,length,array2) removes the corresponding element from the array and replaces it with a new element

array_push() (into the stack) adds one or more elements to the end of the array,

array_pop() (pop) removes the last element from the array

33. What are the methods of cross-domain requests? ?

JSONP

CORS

34. How many storage engines are there? What's the difference? ?

Mysiam and innodb

The MyISAM type does not support advanced processing such as transaction processing, but the InnoDB type does. The MyISAM type of table emphasizes performance, and its execution speed is faster than the InnoDB type, but it does not provide transaction support, while InnoDB provides transaction support and advanced database functions such as external keys. Create an index: alert tabletablename add index (`field name`)

35. Redis default port number? type of data?

6379

String, hash, list (linked list), set (set), zset (ordered set)

36. Redis Practical Cases – Cases of Flash Sales, Counters, Recommendations, Collections

Spike:

Using Redis's list linked list, pop operation, even if many users arrive at the same time, they are executed sequentially

1. Now store the inventory of the product table in the queue

2. The panic buying starts, and the inventory cache period is set

3. The client executes the order operation, and judges the inventory of the redis queue before placing the order

counter:

37. What is the difference between left link and right link in MySQL? ?

Left join (left join): the left table prevails, and the records in the left table will appear in the query results. If there is no matching record in the right table, it will be filled with null.

Right join (right join): The right table prevails, and the records in the right table will appear in the query results. If there is no matching record in the left table, it will be filled with null.

Inner join: The status of the two tables is equal, and the records that meet the join conditions will appear in the query results.

38. What is the default port number of memcache? ? , the difference between Memcache and Redis??

27017,28017

Memcache cache stores all the data in the memory, adopts the method of hash table, and makes each piece of data consist of key and value. Each key is unique. When you want to access a certain value, first find the value, and then Returning the result, Memcache uses the LRU algorithm to gradually clear out expired data

39. mysql lock mechanism

40. What are the aspects of database optimization? ?

1. Designing the database

2. Create an index

3. Read and write separation

4. Cache

41. In an e-commerce project, when will commodity inventory change? ?

1. When adding items, the item inventory increases. Inventory table for different attributes, add

2. When the order payment is successful, the inventory will decrease

3. If the order payment fails, the inventory will not decrease

4. Customer returns and inventory increases

42. Optimize MySQL query

1. Avoid full table query and create indexes for corresponding fields

2. Avoid query sentences that are too long and query in batches.

3. There cannot be function operations behind where

4. The left principle like the first field must have an index

5. Create an index after where and group by

Publisher: Full-stack Programmer Stack Manager, please indicate the source for reprinting: https://javaforall.cn/175595.html Original link: https://javaforall.cn

This article participates in  Tencent Cloud's self-media sharing plan  , and you who love writing are welcome to participate together!

This article is shared from the author's personal site/blog. If there is any infringement, please contact [email protected] to delete it.

おすすめ

転載: blog.csdn.net/2301_78064339/article/details/131152516