Home > Article > Backend Development > Answers to interview questions
The content of this article is about answering interview questions, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
1. Advantages of ajax
Ajax is an asynchronous transmission technology that can be implemented through javascript or the JQuery framework to achieve partial refresh, which reduces the pressure on the server and improves efficiency. User experience
2. Nowadays, the MVC three-layer structure is often used in programming. What are the three layers of MVC? What are the advantages?
The three layers of MVC refer to: business model, view, and controller respectively.
The controller layer calls the model to process the data, and then the data
# and
2. M and V implementation code separation, so that the same program can use different expressions
3.
echo(), The difference between print() and print_r()
## Answer: echo is a PHP statement, print and print_r are functions, statements have no return value, and functions can have return values print() can only print out the value of simple type variables (such as int, string)
print_r() can print out the value of complex type variables (such as array, object)
echo outputs one or more strings
4. What is a transaction, characteristics u
Answer: Transaction: It is a series of database operations and the basic logical unit of database application. Either all transactions are executed, or none are executed.
(2) Consistency. The execution of a transaction converts the database from one correct state to another correct state
(3) Isolation. Before the transaction is correctly committed, any changes to the data made by the transaction are not allowed to be provided to any other transaction,
(4) Durability. After the transaction is properly submitted, the result will be permanently preserved in the database. Even after the transaction is submitted, there will be other faults.
The SQL statement of the working unit is packed. If any statement fails, the entire operation will be failed. To ensure that something is either executed or not executed, transactions can be used. To consider a group of statements as a transaction, you need to pass the ACID test, that is, atomicity, consistency, isolation, and durability.
5. What is a lock?
Answer: When a transaction operates on a data object, it first sends a request to the system to lock it. After locking, the transaction will With certain control, other transactions cannot update this data object before the transaction releases the lock.
effect? And what are its advantages and disadvantages?
Answer: An index is a special query table that the database search engine can use to speed up data retrieval.
The index can be unique. Creating an index allows you to specify a single column or multiple columns.
The disadvantage is that it slows down the speed of data entry and also increases the size of the database.
6. MyISAM type InnoDB type engine difference:
MyISAM type does not support transactions, table locks, and is prone to fragmentation. It must be optimized frequently. The reading and writing speed is faster, and the InnoDB type supports transactions, row locks, and crash recovery capabilities. Read and write speeds are slower than MyISAM.
7. PHP function default modifier
static public
8. What are the characteristics of object-oriented?
. If it is 4 aspects, add: abstraction.
The following explanation is for understanding: ’ ’ s ’ ’ s ’ s to ‐ ‐ ‐
# The goal of encapsulation is to achieve high cohesion and low coupling of software components and prevent the impact of changes caused by program interdependence.
## The content defined by the class is regarded as its own content, and some new content can be added, or the original method can be modified to make it more suitable
to meet special needs. This is inheritance. Inheritance is a mechanism for subclasses to automatically share parent class data and methods. This is a
relationship between classes, which improves the reusability and scalability of software.
The method call issued is not determined during programming, but is determined during the running of the program, that is, which class instance object a reference variable will point to, which reference variable
Methods in which category is used by variables, which must be determined during the operation of the program.
out out out out out of Ignore those aspects that are not relevant to the current topic and goals, and focus on those aspects that are relevant to the current
. For example, if you see an ant and an elephant and you can imagine how they are similar, that is abstraction.
9.
How does the __autoload() method work? Answer: The basic condition for using this magic function is that the file name of the class file must be consistent with the name of the class.
When the program is executed to instantiate a certain class, if the class file is not introduced before instantiation, the __autoload() function will be automatically executed.
This function will find the path of the class file based on the name of the instantiated class. When it is determined that the class file does exist in the path of the class file
Execute include or require to load the class, and then the program continues to execute. If the file does not exist in this path, an error will be prompted.
Using the automatically loaded magic function eliminates the need to write many include or require functions.
10.
What is the behavior in tp3? Behavior performed before the action## Behavior: Behavior, on top of the system core, a lot of label extension bits are set, and each label position can perform its own independent behavior in turn; through the built-in Behavior extensions complete system functions, and all behavior extensions are replaceable and additive.
11.
How to enable debugging mode? What are the benefits of debug mode?
# Answer: It is very simple to turn on the debugging mode. You only need to add a line of constant definition code to the entrance file:
// Open the debug mode
# DEFINE ('App_debug', TRUE);
# After the development stage is deployed to the production environment, you only need to delete the debug mode Define the code to switch to deployment mode.
After turning on debugging mode, the system will first load the system default debugging configuration file, and then load the project’s debugging configuration file. The advantages of debugging mode are:
1. Turn on logging, any error information and debugging information will be recorded in detail to facilitate debugging;
2. Turn off the template cache, template modifications can take effect immediately;
3. Record SQL logs to facilitate SQL analysis;
4. Turn off field caching, data table field modifications will not be affected by the cache;
5. Strictly check file case (even for Windows platforms), helping you discover Linux deployment problems in advance; Application mode can configure independent project configuration files.
12. What are the URL patterns in TP? Which is the default?
Answer: ThinkPHP supports four URL modes, which can be defined by setting the URL_MODEL parameter, including normal mode, PATHINFO, REWRITE and compatibility mode.
The default mode is: PATHINFO mode, set URL_MODEL to 1
13. What is the difference between compilation and caching in Smarty
The compilation process of smarty is to take the template and replace the tags inside with the corresponding php code. In fact, it is the process of mixing php and html
The cache of smarty needs to be turned on manually. The cache of smarty is to After the compiled file is executed, a static html page is generated at the same time.
When you visit again, you will access the html file, so in terms of efficiency, it is higher
13. What is the Smarty caching mechanism?
If caching is enabled, smarty will generate a static html page at the same time. If it does not expire within the set time,
When you visit again, What you are accessing is the html file, which reduces the need to read the database, so in terms of efficiency, it is higher.
14. In the development of the program, how to improve the operating efficiency of the program?
1. Optimize the SQL statement, try not to use select * in the query statement, and use which field to check which field; .
Use less subqueries and can be replaced by table joins; 3.
Use less fuzzy queries 4. Create indexes in the data table;
Generates the cache for the data frequently used in the program;
15. Understanding of JSon data format:
JSON (JavaScript Object Notation) is a lightweight data exchange format,
json data format is fixed,
can Used for data transfer in many languages , bool $assoc ] ),
Accepts a JSON format string and converts it into a PHP variable,
Parameter json is a character in json string format to be decoded string.
# ASSOC When this parameter is True, it will return to Array instead of Object;
# This
#16. Principle of session control:
http is a stateless protocol, this protocol cannot Maintain the connection between two transactions. When a user requests one page and then requests another page, http will not be able to tell us that the two requests came from the same variable. The idea of session control is to be able to track a variable in the website. If we can track the variable, we can support the user and display different content and pages based on authorization and user identity.
17. What do php upload files move_upload_file and is_uploaded_file do?
move_upload_file moves the uploaded file to a new location
is_uploaded_file determines whether the file was uploaded through HTTP POST
18. The storage engine of database Mysql, the difference between myisam and innodb.
The first type:
MyISAM is a non-transactional storage engine; suitable for applications with frequent queries; table locks, no deadlock; suitable Small data, small complication
# This is a storage engine that supports transactions; applications that are more integrated and updated; if the design is reasonable, the lock is locked (the biggest difference is at the level of the lock); Suitable for big data and large concurrency.
The second type:
The MyISAM type does not support transactions, table locks, and is prone to fragmentation. It needs to be optimized frequently and has faster reading and writing speeds, while the InnoDB type supports transactions. , row locking, crash recovery capabilities. Read and write speeds are slower than MyISAM.
19. The difference between char and varchar
Answer: char is a fixed-length character type. It takes up as much space as it allocates. long space.
Varchar is a variable-length character type. It takes up as much space as the content is, which can effectively save space.
Since the varchar type is variable, the server has to perform additional operations when the data length changes, so the efficiency is lower than that of the char type.
20. The MySQL database is used as the storage of the publishing system. The increment of more than 50,000 items per day is expected to be three years of operation and maintenance. How to optimize it?
a. Design a well-designed database structure, allow partial data redundancy, and try to avoid join queries to improve efficiency.
b. Select the appropriate table field data type and storage engine, and add indexes appropriately.
C. Mysql library owner from reading and writing is separated.
d. Find regular tables and reduce the amount of data in a single table to improve query speed.
e. Add caching mechanism, such as memcached, apc, etc.
f.. Generate static pages for pages that don't change frequently.
g. Write efficient SQL. For example, SELECT * FROM TABEL is changed to SELECT field_1, field_2, field_3 FROM TABLE.
21. Object-oriented understanding
Object-oriented OO = Object-oriented analysis OOA Object-oriented design OOD Object-oriented programming OOP;
The popular explanation is that "everything is an object", and all things are regarded as objects. Objects (units) that can be independent,
They can complete their own functions, instead of being divided into functions like C.
The current pure OO languages are mainly Java and C#. PHP and C also support OO. C is process-oriented.
The second type:
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.
22. Briefly describe the access rights of private, protected, and public modifiers.
Answer: private: Private members can only be accessed inside the class.
#: Protective members can be accessed in this class and inheritance class.
Public: Public members, completely public, no access restrictions.
23. What are the concepts and differences between abstract classes and interfaces?
Answer:
Abstract class:
It is a special class that cannot be instantiated. Can be used as a parent class for other classes. Declared using the abstract keyword.
Interface:
It is a special abstract class and a special class, declared using interface.
(1) The operation of an abstract class is implemented by inheriting keyword EXTENDS, and the use of the interface is implemented through iMplements keywords.
(2) There are data members in the abstract class, which can realize data packaging, but there is no data member of the interface.
(3) There can be constructors in abstract classes, but there are no constructors in interfaces.
(4) The method of abstract class can be modified through Private, ProteCTED, Public keywords (abstract methods cannot be private), and the method in the interface can only be modified using Public keywords.
(5) A class can only inherit from one abstract class, and a class can implement multiple interfaces at the same time.
(6) There can be a member method of member methods in the abstract class, and the implementation code of member methods cannot be implemented in the interface.
The second difference:
1. A class with abstract methods is called an abstract class. Abstract classes do not necessarily have only abstract methods. Abstract methods must use the abstract keyword. definition.
## 2, all in the interface are abstract methods, the method does not need to be defined by abstract.
23. When to use the constructor and when to use the destructor
The constructor (method) completes object creation The first method automatically called by the object.
It exists in every declared class and is a special member method.
The function is to perform some initialization tasks. In Php, __construct() is used to declare the constructor method, and only one can be declared.
The destructor (method) is exactly the opposite of the constructor. It is the last method automatically called by the object before it is destroyed.
It is used to perform some specific operations before destroying an object, such as closing files and releasing memory.
24. What is Smarty, advantages and disadvantages
Smarty is a PHP template engine written in PHP. The purpose is It is necessary to use PHP programs to separate them from artists.
This allows programmers to change the logical content of the program without affecting the page design of the artist. When the artist re-modifies the page
It will not affect the program logic of the program, which is particularly important in multi-person cooperation projects. (It is also easy to develop multi-style programs)
## ‐ ‐ ‐ ’ s 1. ’ s 1-S t-template 1. Smarty advantages
#2. Compilation type: The program written by Smarty must be compiled into a non -template technology PHP file
# 3 Caching technology: It can cache the HTML file that the user finally sees into a static HTML page
4. Plug-in technology: smarty can customize plug-ins.
# is not suitable for the place of using Smarty
## 1.
What needs to be updated in real time. For example, like stock display, it needs to update data frequently 2.
Small projects. A small project that requires both an artist and a programmer because of its simplicity
25. Common HTTP status codes:
200 - The request was successful
301 - The resource (web page, etc.) was permanently escaped to another URL
302 - The temporary transfer was successful and the requested content has been moved to the new location
401 - Indicates unauthorized access.
403 - Access Forbidden.
404 - The requested resource (web page, etc.) does not exist
500 - Internal server error
505 - Internal server error
27. What is the difference between passing by value and passing by reference in php, and when to use it?
having being assigned by value by default. That is to say, when our expression is assigned to a variable, A variable
This means that the new variable simply references (in other words, becomes an alias or point to) the original variable. Changes to new variables will affect the original variables and vice versa. To use reference assignment, simply add an ampersand to the variable to be assigned (source variable)
Object default For larger data, it is better to pass by reference, which can save memory overhead
## The second type:
Passing by value: Any changes to the value within the function range will be ignored outside the function
This can be passed by reference Reflecting these modifications
Advantages and Disadvantages: When passing by value, PHP must copy the value. Especially for large strings and objects,
this will be a very expensive operation. Passing by reference does not require copying the value, which is good for improving performance.
28. The difference between double quotes and single quotes
1. Double quotes interpret variables and single quotes Do not interpret variables
2. Insert single quotes between double quotes. If there is a variable within the single quotes, the variable will be explained
3. The variable name must be followed by double quotes There must be a special character other than numbers, letters, or underscores,
or enclose the variable, otherwise the part after the variable name will be treated as a whole, causing a syntax error
4 . Double quotes interpret escape characters, single quotes do not interpret escape characters, but interpret '\ and \\
5. can make single quote characters use single quotes as much as possible. The efficiency is higher than double quotes (
Because double quotes need to be traversed first to determine whether there are variables in them before operating, while single quotes do not need to be judged)
29. Where is the user behavior log cache? MongoDB
##1. Commonly used super global variables
$_GET ----->get transmission method
## $ g Globals ----- & gt; All variables are placed in it
$_file ------ & gt; upload files
$_SERVER ----->System environment variables
$_SESSION ----->Session controlled
will be used when doing so $_COOKIE ----->It will be used during session control
## $_ENV ------- ->Environment variables
2. The difference between version control tool SVN and Git
1.
Git is distributed, svn It is centralized .
2. svn must have a central server, git does not need .
# 4.
Git facilitates switching between branches . 5.
The integrity of git is better than svn
3. 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, it returns false. Empty determines whether the variable is empty and false. Only one variable can be passed. If it is empty, it returns true.
4. explode and implode split strings and connect arrays
5. What processes does file_get_contents go through? Read the contents of the file into a string
6. What is the difference between make and make install under Linux? Compile and install
7. In object-oriented, can interfaces inherit interfaces? Yes, but the interface cannot inherit the class
8. The difference between Memcache and Redis
1. Data type
Redis has rich data types. Supports set list and other types
but memcache Support persistent data storage
having to being made to be the holder of persistent data that Model
# Memcache can use consistency haSh to do distribution
4. value Different size is different
Memcache is a memory cache, Key’s The length is less than 250 characters, and the storage of a single item is less than 1M, which is not suitable for virtual machines
5. Different data consistency
Redis uses a single-threaded model to ensure The data is submitted in order.
Memcache needs to use cas to ensure data consistency. CAS (Check and Set) is a mechanism to ensure concurrency consistency and belongs to the category of "optimistic locking"; the principle is very simple: take the version number, operate, compare the version number, if it is consistent, operate, if not, abandon any operation
6. cpu utilization
The redis single-threaded model can only use one CPU and can open multiple redis processes
9. What is Serialization? What is the function?
Formulating string and converting into an array or object
# Serialize () serialization
1. TP, LAVAREL, YII differences
[TP YII CI Framework Comparison - CSDN Blog](http://blog.csdn.net/pangchengyong0724/article/details/49246847)
2. Construction of CI principle? What version are you using (3.1.7 stable version)
Before the program is executed, the framework will load Hooks, mainly to determine whether the config has enabled hooks, If turned on, load the config/hoos.php configuration file and hook configuration information;
Then the framework calls hoosk by calling the hooks->call method, and the hook class parses the configuration through call_hook. Call the function through run_hook in the hook class;
4. Explain what php is?
is the abbreviation of the English hypertext preprocessing language PHP: Hypertext Preprocessor.
PHP is an HTML embedded language. It is a scripting language embedded in HTML documents that is executed on the server side.
The style of the language is similar to C language is widely used.
5.
The difference between include and require If the imported file in include does not exist, it will report a warning if it tries to continue execution.
However, if the imported file in require does not exist, it will report a fatal error and will not continue execution.
6. The difference between mysql_fetch_assoc and mysql_fetch_array
//mysql_fetch_array gets a row from the result set as an associative array, a numeric array, or both
Contains only values, we can only $row[0],$row[1], so we can read the data with array subscripts,
to be read by using the array subscript. , also includes the form of key-value pairs, we can read the data like this, (if the database fields are username, passwd): $row['username']$row['passwd']
7. Can the session be saved to the database?
# 能
## This function is the serialization? What is the format? What to use for conversion?
# Serialize () serialize arrays into a key-value structure with a bracket string
## // unSerialize () back serialization Become an array
11. Return to the previous page go(-1)
12. Can js operate cookies? Yes, set cookie: setcookie; get cookie: getcookie
13. The dollar$ function is encapsulated in jQ and represents jquery
in jQ. Related recommendations:
php interview summary
The above is the detailed content of Answers to interview questions. For more information, please follow other related articles on the PHP Chinese website!