Home Backend Development PHP Tutorial Advanced PHP interview questions and some answers_PHP tutorial

Advanced PHP interview questions and some answers_PHP tutorial

Jul 14, 2016 am 10:09 AM
php Can exist of Answer test questions part interview advanced

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles