Common interview topics in PHP

Source: Internet
Author: User
Tags echo date flock flock lock types of tables vars

I. Basic knowledge points
1.1 The meaning 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 with it.
301: Permanent redirect.
302: Temporary row redirection.
401: The current request requires user authentication.
403: The server refuses to execute the request, that is, no permissions.
404: The request failed and the requested data was not found on the server.
500: Server error. General server-side program execution error.
503: The server is temporarily maintained or overloaded. This state is temporary.

1.2 Include require include_once require_once the difference.
Processing failed in different ways:
Require fails with a fatal level error and stops the program from running.
The include fails with only a warning level error, and the program continues to run.

Include_once/require_once and Include/require handle the wrong way,
The only difference is that when the included file code already exists, it is not contained.

1.3 (MySQL) please write the meaning of the data type (int char varchar datetime text); What is the difference between varchar and char, please?
int: Numeric type
Char: fixed-length string type
VARCHAR: variable-length string type
DateTime: Period Time Type
Text: literal type

What is the difference between varchar and char:
A. Char length is fixed, regardless of the amount of data you store, he will be fixed length.
The varchar is variable in length but he adds 1 characters to the total length, which is used to store the location.

B. Char fixed length, so the processing speed is much faster than varchar, but a waste of storage space,
Therefore, the storage is not small, but the speed of the requirements can use the char type, and vice versa can be used to instantiate the type of varchar.

1.4 Error_reporting and other debugging functions use
The error_reporting () function can set the error_reporting instruction in php.ini at run time.
So you can adjust the level of error displayed at any time in the program.
The display_errors must be open when using this function.

1.5 Write code to solve the problem of multi-process/thread reading and writing a file at the same time.
PHP does not support multithreading, you can use the PHP flock lock function implementation.
$fp = fopen ("/tmp/lock.txt", "w+");
if (Flock ($FP, LOCK_EX)) {//row-type locking
Fwrite ($fp, "Write something here\n");
Flock ($FP, lock_un); Release lock
} else {
echo "couldn ' t lock the file!";
}
Fclose ($FP);

1.6 Write the code to upload the file.
Upload.html
<form enctype= "Multipart/form-data" method= "POST" action= "upload.php" >
Send This file: <input name= "name" type= "file"/>
<input type= "Submit" value= "Send File"/>
</form>

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's storage engine, the difference between MyISAM and InnoDB.
A. MyISAM types do not support advanced processing, such as transaction processing, and InnoDB type support.
B. MyISAM types of tables emphasize performance, which is performed more quickly than the InnoDB type.
C. InnoDB does not support indexes of fulltext types.
D. InnoDB does not save the exact number of rows in the table, that is,
When you execute SELECT COUNT (*) from table, InnoDB to scan through the entire table to calculate how many rows,
But MyISAM simply reads out the number of saved rows.
E. For fields of type auto_increment, InnoDB must contain only the index of the field, but in the MyISAM table, you can establish a federated index with other fields.
F. Delete from table, InnoDB does not reestablish the table, but deletes one row at a time.
G. LOAD table from master operation does not work for InnoDB, the solution is to change the InnoDB table to MyISAM table first, import the data and then change to the InnoDB table,
However, tables that use additional InnoDB attributes, such as foreign keys, do not apply.
H. MyISAM supports table locks, InnoDB supports row locks.

Two. Web architecture, security, project experience

2.1 MySQL database for the storage of the publishing system, more than 50,000 increments per day, estimated operations three years, how to optimize?
A. Well-designed database structure, allowing partial data redundancy, to avoid join query, improve efficiency.
B. Select the appropriate table field data type and storage engine, and add the index as appropriate.
C. mysql Library master-slave read/write separation.
D. Find regular tables and reduce the amount of data in a single table to improve query speed.
E. Add caching mechanisms, such as MEMCACHED,APC.
F. Pages that do not change frequently, generating static pages.
G. Writing high-efficiency SQL. For example, select * from Tabel to select Field_1, Field_2, field_3 from TABLE.

2.2 For large traffic sites, what kind of method do you use to solve the statistic problem of each page access quantity?
A. Confirm that the server can support the current traffic.
B. Optimize database access. Reference 2.3
C. prohibit external access link (hotlinking), than slice hotlinking.
D. control file download.
E. Use different host shunts.
F. Use the Browse statistics software to understand the volume of visits, targeted optimization.

2.3 Write a regular expression that js/vbs all the scripts on the Web page (that is, remove the tags and their contents): (9).

Answer:/<[^>].*?>.*?<\/>/SI

2.4 Using PHP to print out the day before the format is 2006-5-10 22:21:21

Answer: Echo date (' y-m-d h:i:s ', Strtotime ('-1 day '));

2.5 echo (), print (), Print_r () difference

Answer: ECHO is the language structure, no return value, print function and echo basically the same, the difference is that print is a function, there is a return value; Print_r is a recursive print for outputting array objects

2.6 How do I implement string flipping?

A: With Strrev function Bai, do not use PHP built-in on their own write:

[PHP]View Plaincopy
  1. Strrev ($str)
  2. {
  3. $len =strlen ($str);
  4. $newstr = ";
  5. For ($i =$len; $i >=0; $i--)
  6. {
  7. $newstr. = $str {$i};
  8. }
  9. return $newstr;
  10. }




2.7 Implementation of the text string interception without garbled method.

Answer: MB_SUBSTR ()

2.8 How to get the content of a Web page address with PHP environment variables? How do I get an IP address?

Answer: $_servsr[' Request_uri ', $_server[' REMOTE_ADDR ']

2.9 for two dates, for example, 2007-2-5 ~ 2007-3-6 Date Differential

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

2.10 How to tell if a window has been blocked by JavaScript

A: Gets the return value of open (), or null if it is blocked

Common interview topics in PHP

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.