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

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

百度高级搜索怎么用百度搜索引擎是目前中国最常用的搜索引擎之一,它提供了丰富的搜索功能,其中之一就是高级搜索。高级搜索可以帮助用户更精确地搜索到所需的信息,提高搜索效率。那么,百度高级搜索怎么使用呢?第一步,打开百度搜索引擎首页。首先,我们需要打开百度的官方网站,即www.baidu.com。这是百度搜索的入口。第二步,点击高级搜索按钮。在百度搜索框的右侧,有

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
