Advanced PHP interview questions and some answers_PHP tutorial

WBOY
Release: 2016-07-14 10:09:56
Original
1072 people have browsed it

I saw some senior PHP interview questions online. .

Having nothing to do, I came up with some answers. . . It may not be comprehensive, so I’ll save it for later.

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 redirection.
401: The current request requires user authentication.
403: The server refuses to execute the request, that is, there is no 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 The difference between Include require include_once require_once.
Failures are handled differently:
Failure of require will generate a fatal level error and stop the program from running.
When include fails, only a warning level 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 no longer included.

1.3 The evolutionary history of several versions of PHP/Mysql, such as major improvements from mysql4.0 to 4.1, PHP 4.x to 5.1, etc.


1.4 HEREDOC Introduction
A way to define a string.
Structure:
<<<. After the prompt, define an identifier (a separate line),
Then a new line. Next is the string itself,
Finally, use the previously defined identifier as the end mark (a separate line)
Note:
The naming of identifiers must also comply with PHP rules like other tags:
Can only contain letters, numbers and underscores, and must start with a letter and an underscore


1.5 Write some PHP magic methods;
__construct() is automatically called when a class is instantiated.
__destruct() is automatically called when the class object is used.
__set() is called when assigning a value to an undefined property.
__get() is called when calling an undefined property.
__isset() is called when using isset() or empty() function.
__unset() will be called when using unset().
__sleep() is called when serializing using serialize.
__wakeup() is called when deserializing using unserialize.
__call() is called when calling a method that does not exist.
__callStatic() calls a static method that does not exist.
__toString() is called when converting an object into a string. Such as echo.
__invoke() is called when trying to invoke an object as a method.
__set_state() is called when using the var_export() function. Accepts an array parameter.
__clone() is called when using clone to copy an object.

1.6 Some configure parameters when compiling php
–prefix=/usr/local/php PHP installation directory
–with-config-file-path=/usr/local/php/etc Specify the location of php.ini
–with-mysql=/usr/local/mysql mysql installation directory, support for mysql
–with-mysqli=/usr/local/mysql/bin/mysql_config mysqli file directory, optimized support
–enable-safe-mode Turn on safe mode
–enable-ftp Turn on ftp support
–enable-zip Turn on support for zip
–with-bz2 Turn on support for bz2 files
–with-jpeg-dir Turn on support for jpeg images
–with-png-dir Turn on support for png images
–with-freetype-dir Turn on support for freetype font library
–without-iconv turns off the iconv function and converts between character sets
–with-libxml-dir Turn on support for libxml2 library
–with-xmlrpc Open the c language of xml-rpc
–with-zlib-dir Turn on zlib library support
–with-gd Turn on gd library support

You can use ./configure help to view more

1.7 Three ways to pass parameters to php.

/*
* Method 1 Use $argc $argv
* Run from the command line /usr/local/php/bin/php ./getopt.php -f 123 -g 456
*/
// if ($argc > 1){
//         print_r($argv);
// }


/**
* Operation results
*
sync@MySUSE11:~/web_app/channel3/interface> /usr/local/php/bin/php ./getopt.php -f 123 -g 456
        Array
(
                                              [0] => ./getopt.php
[1] = & gt; -F
                                         [2] => [3] = & gt; -g
[4] = & gt; 456
)
​​*/

/*
* Method 2 Use getopt function ()
* Run from the command line /usr/local/php/bin/php ./getopt.php -f 123 -g 456
*/

// $options = "f:g:";
// $opts = getopt( $options );
// print_r($opts);

/**
* Operation results
*
sync@MySUSE11:~/web_app/channel3/interface> /usr/local/php/bin/php ./getopt.php -f 123 -g 456
        Array
(
[F] = & gt; 123
                                                                                                                                                                    [g] => 456
)
​​*/

/*
* Method 3: Prompt the user for input, and then obtain the input parameters. A bit like C language
* Run from the command line /usr/local/php/bin/php ./getopt.php
*/
fwrite(STDOUT, "Enter your name: ");
$name = trim(fgets(STDIN));
fwrite(STDOUT, "Hello, $name!");
/**
     * 运行结果
     *
     sync@MySUSE11:~/web_app/channel3/interface> /usr/local/php/bin/php ./getopt.php
     Enter your name: francis
     Hello, francis!
    */


1.8 (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 the processing speed is much faster than varchar, but it wastes storage space,

Therefore, if the storage is not large, but the speed is required, you can use the char type, and conversely, you can use the varchar type to instantiate.

1.9 Use error_reporting and other debugging functions
The error_reporting() function can set the error_reporting directive in php.ini at runtime.
Therefore, the displayed error level can be adjusted at any time in the program.
display_errors must be turned on when using this function.

1.10 Have you ever used version control software? If so, what is the name of the version control software you used?


1.11 The difference between posix and perl standard regular expressions;

1.12 Which places are restricted after Safe_mode is turned on.

Enabling safe_mode will restrict many PHP functions, especially system-related file opening, command execution and other functions.
All functions that operate on files will only operate on files with the same UID as the script.

1.13 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 lock
fwrite($fp, "Write something here");
flock($fp, LOCK_UN); // Release lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);


1.14 Write a code to upload files.
upload.html


Send this file:

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.15 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 does not support FULLTEXT type index.
d. InnoDB does not save the specific number of rows in the table, that is,
When executing select count(*) from table, InnoDB needs 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, a joint index can be established with other fields.
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 on InnoDB. The solution is to first change the InnoDB table to a MyISAM table, then import the data and then change it to an InnoDB table,
But it does not apply 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, project experience
2.1 Introduce the experience of using xdebug, apc, eAccelerator, Xcache, Zend opt.


2.2 When using mod_rewrite, if there is no physical file /archivers/567.html on the server, it will be redirected to index.php?id=567. Please turn on mod_rewrite first.
First, open the mod_rewrite module.

Secondly, http.conf finds the following code snippet:

Options FollowSymLinks
AllowOverride None

Change: AllowOverride None to AllowOverride All and restart the httpd service.

Then, create a .htaccess file in the project root directory and fill in the rules.

2.3 The MySQL database is used as the storage of 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. The master-slave reading and writing of the mysql library are separated.
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, etc.
f. For pages that do not change frequently, static pages are generated.
g. Write efficient SQL. For example, SELECT * FROM TABEL is changed to SELECT field_1, field_2, field_3 FROM TABLE.


2.4 Write a sorting algorithm (principle) and state how to optimize it.


2.5 Please briefly describe your most proud development work


2.6 For websites with large 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 volume.
b. Optimize database access. Reference 2.3
c. Prohibit external access to links (hotlinking), such as hotlinking of pictures.
d. Control file downloads.
e. Use different hosts to distribute traffic.
f. Use browsing statistics software to understand the number of visits and carry out targeted optimization.


2.7 Have you ever used a template engine? If so, what is the name of the template engine you used?
Smarty

2.8 Please introduce the principle of Session. What should we pay attention to in terms of Session in large websites?


2.9 Tools for testing PHP performance and MySQL database performance, and methods to find bottlenecks.


2.10 Propose all links in a web page.


2.11 Introduce the principles of common SSO (single sign-on) solutions (such as dedecms integrating discuz's passport).


2.12 What are the characteristics of the PHP framework you have written, what problems does it mainly solve, and how is it different from other frameworks.


2.13 What are the differences in performance optimization between large forums/news article systems/SNS websites?


2.14 Photo album applications: It is required that multiple files can be selected and uploaded at the same time in the browser, pictures must be cropped, and the compressed package must be decompressed on the server side. Can upload a single file up to 50M. A progress bar is displayed during the upload process. Thumbnails of four sizes can be generated for each picture, and the video files must be converted into flv for flash playback. Describe the various types of open source software to be covered and their simple uses.
A group of monkeys line up in a circle and are numbered according to 1, 2,..., n. Then start counting from the 1st one, count to the mth one, kick it out of the circle, start counting from behind it, count to the mth one, kick it out..., and continue in this way until the end. Until there is only one monkey left, that monkey is called the king. Programming is required to simulate this process, input m, n, and output the number of the last king. Use a program to simulate this process.


3. Basic use of unix/linux
3.1 Some methods to view the current system load information under Linux.


3.2 Basic shortcut keys for vim.


3.3 SSH security enhancement method; configuration of password mode and rsa key mode.


3.4 rpm/apt/yum/ports Basic commands for package installation, query, and deletion.


3.5 Basic format of Makefile, gcc compilation, connection commands, difference between -O0 and -O3.


3.6 Basic use of gdb, strace, and valgrind.


4. Front-end, HTML, JS
css box model.
prototype in javascript.
The scope of this object in JavaScript.
The difference in event bubbling between IE and Firefox.
What are weird mode, standard mode, and near-standard mode.
Definition of DTD
Common hacks for IE/firefox.
Firefox, front-end js/css debugging tool under IE.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477584.htmlTechArticleI saw some advanced PHP interview questions online. . I had nothing to do and came up with some answers. . . It may not be comprehensive, so I’ll save it for later. 1. Basic knowledge points 1.1 In the HTTP protocol...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!