PHP common interview questions
These are interview questions I compiled from the Internet. I hope they will be helpful to you when you go out for interviews in the future.
1. Basic knowledge points
1.1 The meanings of several status codes in the HTTP protocol: 503 500 401 403 404 200 301 302. . .
200: The request is successful and the requested data is returned.
301 : Permanent redirect.
302: Temporary line redirection.
401: The current request requires user authentication.
403: The server refuses to execute the request, that is, it does not have permission.
404: The request failed, the requested data was not found on the server.
500: Server error. General server-side program execution errors.
503: The server is temporarily under maintenance or overloaded. This state is temporary.
1.2 Include require include_once The difference between require_once.
Handling failure is different:
When require fails, a fatal level error will be generated and the program will stop running. When
include fails, only a warning level error is generated and the program continues to run.
include_once/require_once handles errors in the same way as include/require.
The only difference is that when the included file code already exists, it is no longer included.
1.3 (mysql) Please write down the meaning of data type (int char varchar datetime text); What is the difference between varchar and char;
int : Numeric type
char : Fixed length string type
varchar : Variable length string type
datetime : Period time type
text : Text type
What is the difference between varchar and char:
a. The length of char is fixed, no matter how much data you store, it will always have a fixed length.
Varchar is of variable length, but it needs to add 1 character to the total length, which is used to store the position.
b. char has a fixed length, so it is much faster than varchar in terms of processing speed, but it wastes storage space.
So the storage is not large, but if you have speed requirements, you can use the char type, and vice versa. Can be instantiated with varchar type.
1.4 Debugging functions such as error_reporting use the
error_reporting() function to set the error_reporting directive in php.ini at runtime.
So you can adjust the displayed error level at any time in the program.
When using this function display_errors must be turned on.
1.5 Write code to solve the problem of multiple processes/threads reading and writing a file at the same time.
PHP does not support multi-threading. You can use PHP's flock locking function to achieve this.
$fp = fopen("/tmp/lock.txt", "w ");
if (flock($fp, LOCK_EX)) { // Perform exclusive locking
fwrite($fp , "Write something here\n");
flock($fp, LOCK_UN); // Release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
1.6 Write a code to upload files.
upload.html
upload.php
$uploads_dir = '/uploads';
foreach ($_FILES["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $ _FILES["tmp_name"][$key];
$name = $_FILES["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
1.7 Mysql storage engine, the difference between myisam and innodb.
a. The MyISAM type does not support advanced processing such as transaction processing, but the InnoDB type does.
b. The MyISAM type table emphasizes performance, and its execution times are faster than the InnoDB type.
c. InnoDB FULLTEXT type indexes are not supported.
d. InnoDB does not save the specific number of rows in the table, that is to say,
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.
e. For fields of type AUTO_INCREMENT, InnoDB must contain an index with only this field, but in the MyISAM table, it can be combined with other fields Create a joint index together.
f. When DELETE FROM table, InnoDB will not re-create the table, but will delete it row by row.
g. The LOAD TABLE FROM MASTER operation does not work for InnoDB. The solution is to first change the InnoDB table to a MyISAM table, and then change it to an InnoDB table after importing the data.
But for the additional InnoDB features used (For example, foreign key) tables are not applicable.
h. MyISAM supports table locks, and InnoDB supports row locks.
2. Web architecture, security, project experience
2.1 The MySQL database is used as the storage for the publishing system. More than 50,000 entries are added in a day. The operation and maintenance is expected to last three years. 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 master-slave reading and writing separation.
d. Find regular tables to reduce the amount of data in a single table and improve query speed.
e. Add caching mechanisms, such as memcached, apc, etc.
f. For pages that do not change frequently, generate static pages.
g. Write efficient SQL. For example, SELECT * FROM TABEL is changed to SELECT field_1, field_2, field_3 FROM TABLE.
2.2 For a website with high traffic, what method do you use to solve the problem of statistics of page visits
a. Confirm whether the server can support the current traffic.
b. Optimize database access. Refer to 2.3
c. Prohibit external access to links (hotlinking), such as hotlinking of pictures.
d. Control file download.
e. Use different hosts to distribute traffic.
f. Use browsing statistics software to understand the number of visits and perform targeted optimization.
2.3 Write a regular expression to filter all JS/VBS scripts on the web page (that is, remove the tags and their contents):
Answer: /<[^>].*?>.*?<\/>/si
2.4 Use PHP to print out the time of the previous day in the format: 2006-5-10 22:21:21
Answer: echo date('Y-m-d H:i:s', strtotime('-1 day'));
2.5 The difference between echo(), print(), and print_r()
Answer: echo is a language structure with no return value; the print function is basically the same as echo The same, but the difference is that print is a function with a return value; print_r is recursive printing, used to output array objects
2.6 Method to implement Chinese string interception without garbled characters
Answer: mb_substr()
2.7 How to use PHP environment variables to get the content of a web page address? How to get the ip address?
Answer: $_SERVSR['REQUEST_URI'], $_SERVER['REMOTE_ADDR']
2.8 Find the difference between two dates, such as 2007-2-5 ~ Date difference of 2007-3-6
Answer: (strtotime('2007-3-6')-strtotime('2007-2-5'))/3600*24
2.9 How to determine whether a window has been blocked through javascript
Answer: Get the return value of open(). If it is null, it means it is blocked
The above are the PHP interview questions I compiled on the Internet. I hope it will be helpful to you when you go out to look for jobs in the future.
Related articles:
PHP interview questions (classic)
The above is the detailed content of PHP common interview questions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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)

Hot Topics











This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
