Common interview topics in PHP

Source: Internet
Author: User
Tags echo date flock flock lock

I. Basic points of knowledge
The meaning of several status codes in the 1.1 HTTP protocol: 503 500 401 403 404 200 301 302 ...
200: The request is successful and the requested data is returned.
301: Permanent redirection.
302: Temporary row redirection.
401: The current request requires user authentication.
403: The server refused to execute the request, that is, no permissions.
404: Request Failed, the requested data was not found on the server.
500: Server error. General server-side program execution error.
503: Server temporary maintenance or overload. This state is temporary.

1.2 Include require include_once require_once differences.
Processing failed in different ways:
Require fails with a fatal level error and stops the program from running.
The include fails with only one 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 contained file code is already present, 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, 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 it will be fixed length.
The varchar is a variable length but he wants to add 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 waste of storage space,
Therefore, the storage is small, but the speed of the requirements can use the char type, and vice versa can be varchar type to instance.

1.4 Error_reporting and other debugging functions using
The error_reporting () function can set the error_reporting instruction in php.ini at run time.
So you can adjust the error level displayed at any time in the program.
Display_errors must be turned on when this function is used.

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 multithreading, you can use PHP's flock lock function implementation.
$fp = fopen ("/tmp/lock.txt", "w+");
if (Flock ($FP, LOCK_EX)) {//Exclusive 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 a piece of 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, MyISAM and InnoDB differences.
A. The MyISAM type does not support advanced processing, such as transaction processing, but InnoDB type support.
B. MyISAM type tables emphasize performance, which is performed more quickly than the InnoDB type.
C. InnoDB does not support indexes of type Fulltext.
D. InnoDB does not save the exact number of rows in the table, that is to say,
When you execute the SELECT COUNT (*) from table, InnoDB scans the entire table to calculate how many rows
But the MyISAM simply reads out the saved rows.
E. For auto_increment type fields, InnoDB must contain an index with only that field, but in the MyISAM table, you can establish a federated index with the other fields.
When you delete the From table, InnoDB does not re-establish the table, but deletes one row at a time.
G. The LOAD table from master operation does not work for InnoDB, the solution is to first change the InnoDB table to MyISAM table, import data and then change to 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 publishing system storage, more than 50,000 increments per day, is expected to transport three years, how to optimize.
A. Design good database structure, allow partial data redundancy, try to avoid join query, improve efficiency.
B. Select the appropriate table field data type and storage engine to add the index appropriately.
C. mysql library master read and write separation.
D. Find the rules of the table, 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 efficient SQL. For example, the select * from Tabel is changed to select Field_1, Field_2, field_3 from TABLE.


2.2 For large traffic sites, what methods do you use to solve the problem of the number of page access statistics
A. Confirm that the server is able to support the current traffic.
B. Optimize database access. Reference 2.3
C. prohibit external access links (hotlinking), such as Picture hotlinking.
D. control file downloads.
E. Use of different mainframe diversion.
F. Use browsing statistics software to understand the number of visits, targeted optimization.


2.3 Write a regular expression, worry about all the Js/vbs script on the page (that is, the tag and its contents are removed): (9).

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

2.4 Use 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

A: Echo is a language structure with no return value; The print function is essentially the same as ECHO, unlike print, which 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 flipping.

A: Use the Strrev function chant, do not use PHP built on their own write:
[PHP] view plain copy strrev ($str) {$len =strlen ($STR);       $newstr = ';       for ($i = $len; $i >=0; $i-) {$newstr. = $str {$i};   return $newstr; }


2.7 Implementation of the text string interception without garbled method.

Answer: MB_SUBSTR ()

2.8 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.9 For two date difference, for example 2007-2-5 ~ 2007-3-6 Date Difference

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


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

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

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.