Common php interview questions

Source: Internet
Author: User
Tags echo date flock
1. Basic Knowledge Point 1.1The meaning of several status codes in http: 503500401403404200301302... 200: the request is successful, and the requested data is returned accordingly. 301: Permanent redirection. 302: Temporary row redirection. 401: the current request requires user verification. 403: the server does not have the permission to execute the request. 404: please

I. Basic knowledge point 1.1 The meaning of several status codes in HTTP: 503 500 401 403 404 200 301... 200: the request is successful, and the requested data is returned accordingly. 301: Permanent redirection. 302: Temporary row redirection. 401: the current request requires user verification. 403: the server does not have the permission to execute the request. 404: please

I. Basic knowledge points
1.1 meaning of several status codes in HTTP: 503 500 401 403 404 200 301 302...
200: the request is successful, and the requested data is returned accordingly.
301: Permanent redirection.
302: Temporary row redirection.
401: the current request requires user verification.
403: the server does not have the permission to execute the request.
404: The request failed. The request data is not found on the server.
500: server error. Generally, the server program execution is incorrect.
503: temporary server maintenance or overload. This status is temporary.

1.2 differences between Include require include_once require_once.
Different Processing failure methods:
When require fails, a fatal error is generated and the program is stopped.
When the include operation fails, only one warning error is generated, and the program continues to run.

Include_once/require_once and include/require handle errors in the same way,
The only difference is that when the included file code already exists, it is not included.


1.3 (mysql) Please write out the meaning of the 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: Time Type
Text: text Type

What is the difference between varchar and char:
A. the char length is fixed. No matter how much data you store, it will be fixed.
Varchar can be a variable in length, but it needs to add 1 character to the total length, which is used to store the location.

B. char has a fixed length, so the processing speed is much faster than varchar, But it wastes storage space,
Therefore, it is not suitable for storage, but the char type can be used for speed requirements. Otherwise, the varchar type can be used for instances.

1.4 Use of error_reporting and other debugging Functions
The error_reporting () function can set the error_reporting command in php. ini at runtime.
Therefore, you can adjust the displayed error level at any time in the program.
When using this function, display_errors must be enabled.

1.5 write code to solve the problem of multiple processes/Threads simultaneously reading and writing a file.
PHP does not support multithreading. You can use php's flock locking function.
$ Fp = fopen ("/tmp/lock.txt", "w + ");
If (flock ($ fp, LOCK_EX) {// sort it to lock
Fwrite ($ fp, "Write something here \ n ");
Flock ($ fp, LOCK_UN); // release lock
} Else {
Echo "Couldn't lock the file! ";
}
Fclose ($ fp );

1.6 write code for uploading a file.
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 What is the difference between the storage engine myisam and innodb of Mysql.
A. The MyISAM type does not support advanced processing such as transaction processing, whereas the InnoDB type does.
B. MyISAM tables emphasize performance, and the execution speed is faster than that of InnoDB tables.
C. InnoDB does not support FULLTEXT indexes.
D. InnoDB does not save the specific number of rows of the table, that is,
When executing select count (*) from table, InnoDB needs to scan the entire table to calculate the number of rows,
However, MyISAM simply needs to read the number of lines saved.
E. For fields of the AUTO_INCREMENT type, InnoDB must contain only the index of this field. However, in the MyISAM table, you can create a joint index with other fields.
F. delete from table, InnoDB does not create a new table, but deletes a row.
G. load table from master operation does not work for InnoDB. The solution is to first change the InnoDB TABLE to the MyISAM TABLE, and then the InnoDB TABLE after the data is imported,
However, it is not applicable to tables that use additional InnoDB features (such as foreign keys.
H. MyISAM supports table locks and InnoDB supports row locks.


2. web architecture, security, and project experience

2.1 MySQL database is used as the storage of the publishing system, with more than 50 thousand increments per day. It is expected to be maintained for three years. How can this problem be optimized?
A. a well-designed database structure allows some data redundancy and avoids join queries as much as possible to improve efficiency.
B. Select the appropriate table field data type and storage engine, and add indexes as appropriate.
C. mysql database Master/Slave read/write splitting.
D. Find regular table shards to reduce the data volume in a single table and increase the query speed.
E. Add cache mechanisms, such as memcached and apc.
F. generate static pages for infrequently modified pages.
G. Write highly efficient SQL statements. For example, SELECT * from tabel is changed to SELECT field_1, field_2, field_3 from table.


2.2 What kind of method do you use to solve the problem of page access statistics for high-traffic websites?
A. Check whether the server can support the current traffic.
B. Optimize database access. Reference 2.3
C. prohibit external access links (leeching.
D. Control File Download.
E. Use different hosts for shunting.
F. Use the browser statistics software to understand the traffic volume and perform targeted optimization.


2.3 write a regular expression and overwrite all JS/VBS scripts on the webpage (that is, remove the mark and its content): (9 ).

A:/<[^>]. *?>. *? <\/>/Si


2.4 print the time format of the previous day in PHP: 22:21:21

A: echo date ('Y-m-d H: I: s', strtotime ('-1 Day '));


2.5 differences between echo (), print (), and print_r ()

A: echo is a language structure and has no return value. The print function is basically the same as echo. The difference is that print is a function and has a return value. print_r is a recursive print that outputs an array object.


2.6 how to implement string flip?

A: Use the strrev function. You are not allowed to write the strrev function using the built-in PHP function:

strrev($str){    $len=strlen($str);    $newstr = '';    for($i=$len;$i>=0;$i--)    {        $newstr .= $str{$i};    }    return $newstr;}



2.7 The method of intercepting Chinese strings without garbled characters is implemented.

A: mb_substr ()


2.8 how can I use the php environment variable to get the content of a webpage address? How can I get the IP address?

A: $ _ SERVSR ['request _ URI '], $ _ SERVER ['remote _ ADDR']


2.9 calculate the difference between two dates, for example,-2-5 ~ Date difference of-3-6

Answer: (strtotime ('2017-3-6 ')-strtotime ('2017-2-5')/2007*24


2.10 how to use javascript to determine whether a window has been blocked

A: Get the return value of open (). If it is null, it is blocked.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.