国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home headlines Summary of common PHP interview questions (with answers)

Summary of common PHP interview questions (with answers)

Feb 23, 2019 am 11:39 AM
php interview questions

This article summarizes some common PHP interview questions (with answers) for everyone. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Summary of common PHP interview questions (with answers)

# I remember the first time I interviewed for the PHP position. I just came out of school and didn’t know what the market was like, and it was zero. Experienced (insert here, zero experience, if you have never been involved in developing a complete or semi-finished project, the company will generally not want you, because the company recruits you because it wants you to help make things. To achieve the improvement of the company's business and performance). At that time, I just said that the trial period was 800 yuan. Of course, it was many years ago! It’s also a pretty low price, so the company just asked for it! ! ! The reason is very simple, everyone knows it!

[Related recommendations: php interview questions (summary)]

When doing projects in a company, growth is a process, and improving your own learning skills is a key The existing. Before entering the company, you will have one or two rounds of interviews and written tests. This is the case for everyone in our industry, so in addition to oral expression skills (being able to speak), there is also strength and ability. This is also what your interview questions require. embodied. There are many types of interview questions, but they are all inseparable from the basics of PHP. Some people who have just come out may not understand the test questions. Let me tell you a method, I actually used it at that time! Just memorize all the question types! The method is very old-fashioned and unrealistic. But it’s very useful, because I’ve encountered all the common question types~~Maybe I’m lucky!

Everyone may learn in their own way! I've been here like that before! Now, we still need to continue to learn and improve our skills, and keep learning as we go! Once you're in a trap, it's hard to get out!

The following recommends some common interview questions, I hope they are useful to you! !

1. Bubble sorting, be sure to remember it before the interview!

function maopao($arr)
{
    $len = count($arr);
    $n = count($arr) - 1;
    for ($i = 0; $i < $len; $i++) {
        for ($j = 0; $j < $n; $j++) {
            if ($arr[$j] > $arr[$j + 1]) {
                $tmp = $arr[$j];
                $arr[$j] = $arr[$j + 1];
                $arr[$j + 1] = $tmp;
            }
        }
    }
    return $arr;
}

2. Quick sort, be sure to remember it before the interview!

function quick_sort($array) {
    if (count($array) <= 1) return $array;
    $key = $array[0];
    $left_arr = array();
    $right_arr = array();
    for ($i=1; $i<count($array); $i++){
        if ($array[$i] <= $key)
            $left_arr[] = $array[$i];
        else
            $right_arr[] = $array[$i];
    }
    $left_arr = quick_sort($left_arr);
    $right_arr = quick_sort($right_arr);
    return array_merge($left_arr, array($key), $right_arr);
}

3. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference?

Pass by value: function Any changes to the value within the scope will be ignored outside the function

Pass by reference: Any changes to the value within the function scope will also reflect these modifications outside the function

Advantages and disadvantages: By reference When a value is passed, php must copy the value. Especially for large strings and objects, this can be an expensive operation. Passing by reference does not require copying the value, which is good for improving performance. (The advantages and disadvantages will be tested)

4. What is the main difference between the field types varchar and char in the MySQL database?

Varchar is a variable Long, saving storage space, char is a fixed length. The search efficiency is faster than that of the char type, because varchar is a non-fixed length, and the length must be searched first, and then the data is extracted, which is one more step than the char fixed-length type, so the efficiency is lower.

5. Common storage engines of MySQL database and their differences?

MyISAM: Does not support transactions, table locks, is prone to fragmentation, must be optimized frequently, has fast read and write speeds, and supports full-text indexing.

InnoDB: supports transactions, row locks, and crash recovery capabilities. The reading and writing speed is slower than MyISAM, and full-text indexing is supported after 5.6.
The storage engine is based on tables, not databases

(This question can be more detailed if possible)

6. For websites with large traffic, what methods are used to solve the traffic problem?

First, confirm whether the server hardware is sufficient to support the current traffic

Secondly, optimize database access.

Third, prohibit external hotlinking.

Fourth, control the download of large files.

Fifth, use different hosts to divert the main traffic

Sixth, use traffic analysis and statistics software

Seventh, try to use static pages and cache

7. What is object-oriented? What are the main features?

Object-oriented is a design method for programs, which helps improve the reusability of programs and makes the program structure clearer. Main features: encapsulation, inheritance, polymorphism.

8. What is the difference between SESSION and COOKIE? This is the key point

SESSION is stored on the server side, and COOKIE is stored on the client side. Session is relatively secure. Cookies can be modified by certain means and are not safe. Session relies on cookies for delivery. After disabling cookies, the session can still be used. In the file that stores the session, the session ID is generated, and the session ID is passed to the page where the session is to be shared through get parameters, and the session ID is read to obtain data from the session.

It is recommended to look for detailed tutorials on session and cookies

9. Do you understand caching technology? redis is a test point

1. Caching technology is to cache dynamic content into files, and access dynamic pages within a certain period of time to directly call the cached files without having to revisit the database.

2. Use memcache for caching.

10. The difference between get and post submission methods in the form

get is explicit, and the data can be seen from the url and transmitted The amount of data is small and the security is low;

post is implicit, the amount of data transmitted is large and the security is high

11. Methods to optimize the database

Select the most applicable field attributes, reduce the width of the defined fields as much as possible, and try to set the fields to NOTNULL

Use connections (JOIN) instead of subqueries

Apply union (UNION) to replace manually created temporary tables

Transaction processing

Lock table, optimize transaction processing

Use foreign keys, optimize lock table

Use indexes

Optimize query statements

12. What is the difference between the statements include and require? What is the difference between the statements include and require?

require is an unconditional inclusion, that is, if require is added to a process, require will be executed first regardless of whether the condition is true. When the file does not exist or cannot be opened, an error will be prompted. And it will terminate the program execution

include has a return value, but require does not (maybe because require is faster than include). If the included file does not exist, an error will be prompted, but the program will Continue to execute

13. What is the difference between redis, memcacahe, and mongoDB?

They are all non-relational databases with very high performance, but mongoDB, memcache and redis are two different types. The latter two are mainly used for data caching. The former is mainly used for querying and storing big data. It is the document-type non-relational database closest to the database.

From the perspective of data storage location, memcache data is stored in memory, while redis can be stored in memory or on disk to achieve the function of persistent storage. Once memcache is powered off, the data If all is lost, redis can use snapshots and AOF to store the data to the disk. When recovering, it can read the data from the disk into the memory. When the physical memory is used up, the data can be written to the disk.

In terms of the type of data stored, memcache and redis store both key-value pairs, but redis values ??have richer types, including string (string), hash (hash), list ( List), set (set) zset (ordered set), and memcache mainly stores strings.

14. Basic variable types of PHP

Four scalar types: boolean (Boolean type), integer (integer type), float ( Floating point type, also called double), string (string)

Two composite types: array (array), object (object)

Finally there are two special types: resource ( Resource), NULL (NULL)

15. How is staticization achieved? How to implement pseudo-static?

1. Staticization refers to page staticization, that is, generating real static files, that is, data can be obtained directly from files without querying the database. It's really static.
There are two main implementation methods:

One is the static file generated when we add information into the database, also known as template replacement technology.

One is that when the user accesses our page, he first determines whether a corresponding cache file exists. If there is a reading cache and there is no reading database, a cache file is generated at the same time.

2、偽靜態(tài)不是真正意義上的靜態(tài)化,之所以使用偽靜態(tài),主要是為了SEO推廣,搜索引擎對動(dòng)態(tài)的文件獲取難度大,不利于網(wǎng)站的推廣。實(shí)習(xí)原理是基于Apache或Nginx的rewrite機(jī)智
主要有兩種方式:

一種是直接在配置虛擬機(jī)的位置配置偽靜態(tài),這個(gè)每次修改完成后需要重啟web服務(wù)器。

另一種采用分布式的,可以在網(wǎng)站的根目錄上創(chuàng)建.htaccess的文件,在里面配置相應(yīng)的重寫規(guī)則來實(shí)現(xiàn)偽靜態(tài),這種每次重寫時(shí)不需要重啟web服務(wù)器,且結(jié)構(gòu)上比較清晰。

16、Mysql的讀寫分離?(進(jìn)階的會遇到)

讀寫分離的實(shí)現(xiàn)原理就是在執(zhí)行SQL語句的時(shí)候,判斷到底是讀操作還是寫操作,把讀的操作轉(zhuǎn)向到讀服務(wù)器上(從服務(wù)器,一般是多臺),寫的操作轉(zhuǎn)到寫的服務(wù)器上(主服務(wù)器,一般是一臺,視數(shù)據(jù)量來看)。當(dāng)然為了保證多臺數(shù)據(jù)庫數(shù)據(jù)的一致性,需要主從復(fù)制。

17、如何處理負(fù)載,高并發(fā)?

1、HTML靜態(tài)化
效率最高、消耗最小的就是純靜態(tài)化的html頁面,所以我們盡可能使我們的 網(wǎng)站上的頁面采用靜態(tài)頁面來實(shí)現(xiàn),這個(gè)最簡單的方法其實(shí)也是最有效的方法。
2、圖片服務(wù)器分離
把圖片單獨(dú)存儲,盡量減少圖片等大流量的開銷,可以放在一些相關(guān)的平臺上,如七牛等
3、數(shù)據(jù)庫集群和庫表散列及緩存
數(shù)據(jù)庫的并發(fā)連接為100,一臺數(shù)據(jù)庫遠(yuǎn)遠(yuǎn)不夠,可以從讀寫分離、主從復(fù)制,數(shù)據(jù)庫集群方面來著手。另外盡量減少數(shù)據(jù)庫的訪問,可以使用緩存數(shù)據(jù)庫如memcache、redis。
4、鏡像:
盡量減少下載,可以把不同的請求分發(fā)到多個(gè)鏡像端。
5、負(fù)載均衡:
Apache的最大并發(fā)連接為1500,只能增加服務(wù)器,可以從硬件上著手,如F5服務(wù)器。當(dāng)然硬件的成本比較高,我們往往從軟件方面著手。

18、說一下單引號雙引號?(基礎(chǔ)考點(diǎn))

單引號內(nèi)部的變量不會執(zhí)行, 雙引號會執(zhí)行

單引號解析速度比雙引號快。

單引號只能解析部分特殊字符,雙引號可以解析所有特殊字符。

19、PHP7的新特性?重點(diǎn)

標(biāo)量類型聲明:PHP 7 中的函數(shù)的形參類型聲明可以是標(biāo)量了。在 PHP 5 中只能是類名、接口、array 或者 callable (PHP 5.4,即可以是函數(shù),包括匿名函數(shù)),現(xiàn)在也可以使用 string、int、float和 bool 了。

返回值類型聲明:增加了對返回類型聲明的支持。 類似于參數(shù)類型聲明,返回類型聲明指明了函數(shù)返回值的類型??捎玫念愋团c參數(shù)聲明中可用的類型相同。

NULL 合并運(yùn)算符:由于日常使用中存在大量同時(shí)使用三元表達(dá)式和 isset()的情況,NULL 合并運(yùn)算符使得變量存在且值不為NULL, 它就會返回自身的值,否則返回它的第二個(gè)操作數(shù)。

use 加強(qiáng):從同一 namespace 導(dǎo)入的類、函數(shù)和常量現(xiàn)在可以通過單個(gè) use 語句 一次性導(dǎo)入了

匿名類:現(xiàn)在支持通過new class 來實(shí)例化一個(gè)匿名類

20、PHP 數(shù)組排序

sort() - 以升序?qū)?shù)組排序

rsort() - 以降序?qū)?shù)組排序

asort() - 根據(jù)值,以升序?qū)﹃P(guān)聯(lián)數(shù)組進(jìn)行排序

ksort() - 根據(jù)鍵,以升序?qū)﹃P(guān)聯(lián)數(shù)組進(jìn)行排序

arsort() - 根據(jù)值,以降序?qū)﹃P(guān)聯(lián)數(shù)組進(jìn)行排序

krsort() - 根據(jù)鍵,以降序?qū)﹃P(guān)聯(lián)數(shù)組進(jìn)行排序

21、建立索引

(普通索引)->
創(chuàng)建:CREATE INDEX <索引名> ON tablename (索引字段)
修改:ALTER TABLE tablename ADD INDEX [索引名] (索引字段)
創(chuàng)表指定索引:CREATE TABLE tablename([...],INDEX[索引名](索引字段))
(唯一索引)->
創(chuàng)建:CREATE UNIQUE <索引名> ON tablename (索引字段)
修改:ALTER TABLE tablename ADD UNIQUE [索引名] (索引字段)
創(chuàng)表指定索引:CREATE TABLE tablename([...],UNIQUE[索引名](索引字段))
(主鍵)->
它是唯一索引,一般在創(chuàng)建表是建立,格式為:
CREATA TABLE tablename ([...],PRIMARY KEY[索引字段])

22、PHP支持多繼承嗎?

不支持。PHP中只允許單繼承,父類可以被一個(gè)子類用關(guān)鍵字“extends”繼承。

23、使用過Memcache緩存嗎,如果使用過,能夠簡單的描述一下它的工作原理嗎?

Memcahce是把所有的數(shù)據(jù)保存在內(nèi)存當(dāng)中,采用hash表的方式,每條數(shù)據(jù)又key和value組成,每個(gè)key是獨(dú)一無二的,當(dāng)要訪問某個(gè)值的時(shí)候先按照找到值,然后返回結(jié)果。
Memcahce采用LRU算法來逐漸把過期數(shù)據(jù)清除掉。

24、優(yōu)化MYSQL數(shù)據(jù)庫的方法

(1)選擇最有效率的表名順序
(2)WHERE子句中的連接順序
(3)SELECT子句中避免使用‘*’
(4)用Where子句替換HAVING子句
(5)通過內(nèi)部函數(shù)提高SQL效率
(6)避免在索引列上使用計(jì)算。
(7)提高GROUP BY 語句的效率, 可以通過將不需要的記錄在GROUP BY 之前過濾掉。

(1).選取最適用的字段屬性,應(yīng)該盡量把字段設(shè)置為NOT NULL
(2).使用連接(JOIN)來代替子查詢(Sub-Queries)
(3).使用聯(lián)合(UNION)來代替手動(dòng)創(chuàng)建的臨時(shí)表
(4).盡量少使用 LIKE 關(guān)鍵字和通配符
(5).使用事務(wù)和外鍵

25、MySQL主從備份的原理?

mysql支持單向、異步復(fù)制,復(fù)制過程中一個(gè)服務(wù)器充當(dāng)主服務(wù)器,而一個(gè)或多個(gè)其它服務(wù)器充當(dāng)從服務(wù)器。

26、error_reporting() 的作用?

設(shè)置 PHP 的報(bào)錯(cuò)級別并返回當(dāng)前級別。

27、如何修改session的生存時(shí)間

在php.ini 中設(shè)置 session.gc_maxlifetime = 1440 //默認(rèn)時(shí)間

代碼實(shí)現(xiàn)

$lifeTime = 24 * 3600;  // 保存一天 
session_set_cookie_params($lifeTime); 
session_start();

28、常見的 PHP 安全性攻擊

SQL注入:用戶利用在表單字段輸入SQL語句的方式來影響正常的SQL執(zhí)行。
防止

使用mysql_real_escape_string()過濾數(shù)據(jù)

手動(dòng)檢查每一數(shù)據(jù)是否為正確的數(shù)據(jù)類型

使用預(yù)處理語句并綁定變量

參數(shù)化SQL:是指在設(shè)計(jì)與數(shù)據(jù)庫鏈接并訪問數(shù)據(jù)時(shí),在需要填入數(shù)值或數(shù)據(jù)的地方,使用參數(shù) (Parameter) 來給值,用@或?來表示參數(shù)。

XSS攻擊 :跨站點(diǎn)腳本攻擊,由用戶輸入一些數(shù)據(jù)到你的網(wǎng)站,其中包括客戶端腳本(通常JavaScript)。如果你沒有過濾就輸出數(shù)據(jù)到另一個(gè)web頁面,這個(gè)腳本將被執(zhí)行。
防止:為了防止XSS攻擊,使用PHP的htmlentities()函數(shù)過濾再輸出到瀏覽器。

CSRF: Cross-site request forgery refers to a request made by a page that looks like a trusted user of the website, but is fake
Prevention: General In other words, make sure the user comes from your form and matches every form you send out. There are two points that must be remembered:

Use appropriate security measures for user sessions, such as updating IDs for each session and using SSL for users.

Generate another one-time token and embed it into the form, save it in the session (a session variable), and check it on submit. For example, _token

code injection in laravel: Code injection is caused by exploiting computer vulnerabilities by processing invalid data. The problem comes when you accidentally execute arbitrary code, usually via file inclusion. Poorly written code can allow a remote file to be included and executed. Like many PHP functions, require can contain a URL or file name.
Prevent code injection

Filter user input

Set disable allow_url_fopen and allow_url_include in php.ini. This will disable the remote files of require/include/fopen

There are many types of questions. I hope you will slowly discover and slowly improve your learning skills during the learning process. Finally, I wish you all a happy study. ! !

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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