2020 latest PHP interview 100 questions (3)

77. Write a few magic methods and explain their effects?

  • __call() A method that will be automatically called when a method that does not exist is called

  • __autoload() will automatically call the second method to load the class file when instantiating an undefined class

  • __set() The method that will be automatically called when assigning a value to an undefined variable

  • __get() Method that will be called automatically when getting the value of an undefined variable

  • __construct()Construction method, the method automatically called when the class is instantiated

  • __destroy() method automatically called when the object is destroyed

  • __unset() A method that is automatically called when unset() is called on an undefined variable

  • __isset() The method that is automatically called when the isset() method is called on an undefined variable

  • __clone() clone an object

  • __tostring() method automatically called when outputting an object

Click to join my penguin group

78. What do $ _REQUEST, $ _POST, $ _GET, $ _COOKIE, $ _SESSION, and $_FILES mean?

They are all PHP predefined variables

  • $_REQUEST is used to get the value submitted by post or get

  • $_POST is used to get the value submitted by post

  • $_GET is used to get the value submitted by get

  • $_COOKIE is used to get the value stored in the cookie

  • $_SESSION is used to get the value stored in the session

  • $_FILES is used to get the value of the upload file form

79. What is the best type of subscript in the array and why?

The subscript of the array is preferably a number type, and the processing speed of the number type is fast.

80. Which of ++i and i++ is more efficient and why?

++i is more efficient than i++ because ++i has one less process to return i.

81. What do magic_quotes_gpc() and magic_quotes_runtime() mean?

Magic_quotes_gpc() is in the php configuration file. If it is set to on, it will automatically escape the strings in POST, GET, COOKIE, and add \ before the '

Magic_quotes_runtime() is a function in php. If the parameter is true, single quotes, double quotes, and backslashes taken from the database will be automatically escaped with backslashes.

82. What are single entrance and multiple entrances in the framework, and the advantages and disadvantages of single entrance?

(1) Multi-entry is to complete user requests by accessing different files.

Single entry means that all requests of a web program point to a script file.

(2) A single entry is easier to control permissions, and it is convenient to perform security checks on http requests.

Disadvantages: URLs do not look so beautiful, especially not friendly to search engines.

83. What are the advantages of your understanding of Memcach?

Memcache is a caching technology that saves dynamic webpages to a file after being parsed within a certain period of time, and the dynamic webpage directly calls this file when it is accessed next time without having to revisit the database. The advantage of using memcache for caching is to improve the access speed of the website and reduce the pressure on the server during high concurrency.

The advantages of Memcache: stability, simple configuration, multi-machine distributed storage, and fast speed.

84. Indexes are a very important concept for relational databases. Please answer a few questions about indexes:

a) What is the purpose of the index?

  • Quickly access specific information in the data table to improve retrieval speed

  • Create a unique index to ensure the uniqueness of each row of data in the database table

  • Connection between accelerometer and table

  • When using grouping and sorting clauses for data retrieval, you can significantly reduce the time for grouping and sorting in the query

b) What is the negative impact of indexes on the database system?

Negative impact: It takes time to create and maintain indexes. This time increases as the amount of data increases; indexes need to take up physical space, not only tables need to take up data space, but each index also needs to take up physical space; Indexes should also be dynamically maintained when adding, deleting, and modifying, which reduces the speed of data maintenance.

c) What are the principles for indexing data tables?

  • Create indexes on the most frequently used fields to narrow the scope of the query

  • Create indexes on fields that are frequently used by Ping and need to be sorted

d) Under what circumstances should it not be indexed?

  • For columns that are rarely involved in the query or columns with many duplicate values, it is not appropriate to create an index

  • For some special data types, it is not appropriate to build indexes, such as text fields (text), where the value range is less known.

84. In web applications, the read frequency of the database is much higher than the write frequency. How to optimize MySQL to deal with this scenario?

Using memcache caching technology, the dynamic data is cached to the file, and the cache file is directly called when the dynamic page is accessed, without having to re-visit the database, thus reducing the number of database queries.

If the website has a lot of visits, you can separate the database read and write servers, use multiple servers to handle database queries, and use fewer servers to handle database writes and modifications.

85. The difference between include and require?

  • include() reads and evaluates every time the file is executed

  • The require() file is processed only once (in fact, the content of the file replaces the require() statement)

  • require() is usually placed at the top of the PHP script program

  • The use of include() is the same as require(). It is generally placed in the processing section of process control. When the PHP script file reads the include() statement, the file it contains is read in. In this way, the program can be executed. Simplification of the process

  • The require() and include() statements are language structures, not real functions, and can be like other language structures of PHP

  • The include_once() and require_once() statements also include and run the specified file during the execution of the script.The only difference with include()require() is that if the code in the file has been included, it will not be included again.

  • require() include file failed, stop execution, give error (fatal)

  • include() is often used for dynamic inclusion.

  • Usually the file is automatically loaded, even if the loading error occurs, the entire program continues to execute

  • One page statement, another page call

  • The envelope file failed, continue to execute downward, and return a warning

86. The difference between single quotes and double quotes in PHP strings?

Single quotes cannot explain variables, while double quotes can explain variables.

Single quotes cannot escape characters, and double quotes can escape characters.

87. What is the purpose of template engines in PHP? Which template engines have you used?

The purpose of using the template engine is to separate the logic code of the program from the html interface code, which makes the structure of the program clearer.

Template engine used: Smarty, ThinkTemplate of ThinkPHP

88. Point out the SQL injection vulnerabilities and solutions in the following code snippets (magic_quotes_gpc = off)

mysql_query(“select id,title from content where catid={
    
    $_GET[catid]}and title like ’%$_GET[keywords]%’”, $link);

Injection vulnerabilities mainly exist in the data submitted by users. The injection vulnerabilities here are mainly GET [catid] and _GET[catid] andGET[catid]_GET[keyword]

Solve injection vulnerabilities:

$_GET[catid]=intval($_GET[catid]);
$sql=”select id,title from content where catid={
    
    $_GET[catid]}and title like ’%$_GET[keywords]%;
$sql=addslashes($sql);
Mysql_query($sql);

89. Point out the functions of the magic_quotes_gpc and magic_quotes_runtime parameters in php.ini.

The function of Magic_quotes_gpc is to use addslashes() to automatically escape on POST, GET, and COOKIE data.

The function of the Magic_quotes_runtime parameter is to set the state. When the state is 0, the automatic escaping is turned off, and when the state is set to 1, the automatic escaping is set. The single quotes, double quotes, and backslashes taken from the database are converted with backslashes. Righteousness.

90. Write the running result of the following php code:

function foo($i) {
    
    
$i++;
echo $i ;
}
function bar(&$i) {
    
    
}
$i = 10 ;
echo $i++ , ++$i; 输出:10,12
foo($i); 输出:13
bar($i); 输出:无输出

91. How to quickly download a picture file on a remote http server to the local?

$file=”";
$fp=fopen($file,’rb’);
$img=fread($fp,10000);
$dir=./;
$local=fopen($dir./.basename($file),’w');
Fwrite($local,$img);

92. What is a timestamp? How to get the current timestamp?

The timestamp is the number of seconds from 00:00:00 on January 1, 1970 to the specified date.

Get the current timestamp: time()

93. Do you understand XSS attacks? How to prevent them?

XSS is a cross-site scripting attack. It first uses cross-site scripting vulnerabilities to execute scripts constructed by the attacker in a privileged mode, and then uses insecure Activex controls to perform malicious actions.

Use the htmlspecialchars() function to filter the submitted content and materialize the special symbols in the string.

94. What are the causes of SQL injection vulnerabilities? How to prevent them?

Reasons for SQL injection: In the process of program development, care is not taken to standardize the writing of sql statements and filter special characters, causing the client to submit some sql statements through global variables POST and GET for normal execution.

Prevent SQL injection:

  • Enable the magic_quotes_gpc and magic_quotes_runtime settings in the configuration file

  • Use addslashes for sql statement conversion when executing sql statement

  • Try not to omit small quotes and single quotes when writing Sql statements

  • Filter out some keywords in the SQL statement: update, insert, delete, select, *

  • Improve the naming skills of database tables and fields. Name some important fields according to the characteristics of the program, and choose the ones that are not easy to guess.

  • Set register_globals to off in the Php configuration file, turn off global variable registration

  • Control the error message, do not output the error message on the browser, write the error message to the log file.

95. How many bits does a byte occupy? How many bytes does an IPv4 address occupy? What about an IPv6 address?

One byte occupies 8 bits, one IPV4 occupies 4 bytes, and one IPV6 occupies 16 bytes.

96, M ADSL broadband connection, ideally, what is the maximum download speed in KB/s?

256KB/s

97. Please write a regular expression to match the image address in the tag in an HTML file

$url=””;
//

98、Fatal error: Call to undefined method ge_user() in /website/index.php on line 39

Called the undefined method ge_user(), check whether this method is defined in the program

99、Fatal error: Class ’client’ not found in /website/index.php on line 173

The class client is not found, check whether there is a client class in the file, or whether it contains a client class file

Warning: Cannot modify header information - headers already sent by (output started at /website/index.php:1) in /website/index.php on line 3

Prompt that there is output in front of the file, check whether there is output or encoding

100、Warning:session_start(): open(/website/tmp/sess_47e067121facf033785f9a1cb16d243b, O_RDWR) failed: No such file or directory (2) in /website/index.php on line 10

No file or directory found, check if the file exists

Pay attention, don't get lost

Alright, everyone, the above is the entire content of this article. The people who can see here are all talents . As I said before, there are a lot of technical points in PHP, because there are too many, it is really impossible to write, and you will not read too much after writing it, so I will organize it into PDF and documents here, if necessary Can

Click to enter the secret code: PHP+「Platform」

Insert picture description here

Insert picture description here


For more learning content, please visit the [Comparative Standard Factory] excellent PHP architect tutorial catalog, as long as you can read it to ensure that the salary will rise a step (continuous update)

The above content hopes to help everyone . Many PHPers always encounter some problems and bottlenecks when they are advanced. There is no sense of direction when writing too much business code. I don’t know where to start to improve. I have compiled some information about this, including But not limited to: distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, laravel, YII2, Redis, Swoole, Swoft, Kafka, Mysql optimization, shell scripts, Docker, microservices, Nginx, etc. Many knowledge points, advanced advanced dry goods, can be shared with everyone for free, and those who need can join my PHP technology exchange group

Guess you like

Origin blog.csdn.net/weixin_49163826/article/details/108956022