亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home headlines Summary of the latest PHP interview questions in 2023 (with answers)

Summary of the latest PHP interview questions in 2023 (with answers)

Feb 23, 2019 am 10:53 AM
php interview questions

Summary of the latest PHP interview questions in 2023 (with answers)

Related recommendations: "2022 PHP Interview Questions Summary (Collection)"

1. Please introduce yourself?

Answer: My name is xxx, from Beijing. I graduated from the Computer Department of xx University in 20xx. After graduation, I worked in PHP development in Wuhan for x years. At work, the company is an outsourcing company, mainly engaged in WeChat development, public account promotion, mall, and forum development

2. What projects are you responsible for in the company?

Answer : Since our company is an outsourcing company, it is impossible to only do one project. The company's projects are all cross-cutting. I have done forums, WeChat, and shopping malls?

3. Why did you come to Shenzhen? ?

Answer: Because my brother is here, my parents also want to take care of each other, and Shenzhen is a first-tier city, and the technology is more cutting-edge than Guangxi

4 .What front-end and back-end frameworks are used in Wuhan?

Answer: Answer according to your own region

5.What modules have you done?

Answer: Login registration, product management, shopping cart module, order management

6. What framework does your company use?

Answer: Our company adopts It is the TP framework, which is developed using mysql apache php, because the TP framework is a free open source, lightweight php development framework, and it was developed by the Chinese ourselves and is also used more domestically. Various materials are also Relatively complete

7.What is mvc? What is the relationship between them?

Answer: mvc is a development model, which is mainly divided into three parts: m(model ), which is the model, is responsible for the operation of data; v (view), which is the view, is responsible for the display of the front and backends; c (controller), which is the controller, is responsible for the business logic

Client request project Controller, if data is needed during execution, the controller will obtain the data from the model, and then display the obtained data through the view

8. What is oop?

Answer: oop is object-oriented programming, which is a computer programming architecture. A basic principle of OOP is that a computer program is composed of a single unit or object that can function as a subroutine.

OOP具有三大特點(diǎn)

1. Encapsulation: Also known as information hiding, it means to separate the use and implementation of a class, leaving only some interfaces and methods to connect with the outside, or only exposing some methods for developers to use. . Therefore, developers only need to pay attention to how this class is used, rather than its specific implementation process. This can achieve MVC division of labor and cooperation, effectively avoid interdependence between programs, and achieve loose coupling between code modules.

2. Inheritance: subclasses automatically inherit the properties and methods of their parent class, and can add new properties and methods or rewrite some properties and methods. Inheritance increases code reusability. PHP only supports single inheritance, which means that a subclass can only have one parent class.

3. Polymorphism: The subclass inherits the properties and methods from the parent class and rewrites some of the methods. Therefore, although multiple subclasses have the same method, objects instantiated by these subclasses can obtain completely different results after calling these same methods. This technology is polymorphism. Polymorphism increases software flexibility.

1. Easy to maintain

The structure is designed with object-oriented thinking and is highly readable. Due to the existence of inheritance, even if the requirements change, the maintenance is only in local modules, so maintenance is Very convenient and lower cost.

2. High quality

When designing, existing classes that have been tested in the field of previous projects can be reused so that the system meets business needs and has high quality. .

3. High efficiency

During software development, things in the real world are abstracted and classes are generated according to the needs of the design. Using this method to solve problems is close to daily life and natural way of thinking, which will inevitably improve the efficiency and quality of software development.

4. Easy to expand

Due to the characteristics of inheritance, encapsulation, and polymorphism, a system structure with high cohesion and low coupling is naturally designed, making the system more flexible, easier to expand, and cost-effective lower.

9. What is smarty and what does it do?

Answer 1: smarty is a template engine written in PHP and is currently the most famous PHP template engine in the industry. One

It separates the logic code and the external display, providing an easy-to-manage and use method to separate the mixed PHP logic code from the HTML code

Answer Two: smarty is one of the most famous engine frameworks in PHP. Our company uses the TP framework, which has encapsulated the smarty template, so it has not been used alone.

Answer three: smarty is a template engine, the most obvious The best place is to cache templates. Generally speaking, templates are made to make a static page, and then cut some dynamic parts inside with any delimiters, then open the template file in PHP, replace the values ????in the delimiters, and then output it, you You can look at the template part in PHPLib.

而smarty設(shè)定了緩存參數(shù)以后,第一次運(yùn)行時(shí)候會(huì)把模板打開,在php替換里面值的時(shí)候把讀取的html和php部分重新生成一個(gè)臨時(shí)的php文件,這樣就省去了每次打開都重新讀取html了。如果修改了模板,只要重新刷下就行了。

10.TP框架有哪些優(yōu)點(diǎn)?

答:TP框架是我們中國人自己開發(fā)的框架,各種資料比較齊全,國內(nèi)用的比較多,比較簡單和方便,而且是免費(fèi)開源的

11.TP的特性有哪些?

1.多表查詢非常方便,在model中幾句代碼就可以完成對多表的關(guān)聯(lián)操作
2.融合了smarty模板,使前后臺分離
3.支持多種緩存技術(shù),尤其對memcache技術(shù)支持非常好
4.命名規(guī)范,模型,視圖,控制器嚴(yán)格遵循命名規(guī)則,通過命名一一對應(yīng)
5.支持多種url模式
6.內(nèi)置ajax返回方法,包括xml,json,html等
7.支持應(yīng)用擴(kuò)展,類庫擴(kuò)展,驅(qū)動(dòng)擴(kuò)展等

12.TP框架中的大字母函數(shù)?

U:對url的組裝
A:內(nèi)部實(shí)例化控制器
S:緩存處理
R:調(diào)用某個(gè)控制器的操作方法
D:實(shí)例化自定義模型類
M:實(shí)例化基礎(chǔ)模型類
I:獲取參數(shù)
L:設(shè)置或者獲取當(dāng)前語言
C:設(shè)置或獲取,保存配置

13.請介紹一下laravel框架?

答: laravel框架的設(shè)計(jì)思想比較先進(jìn),非常適合應(yīng)用各種開發(fā)模式,作為一個(gè)框架,它為你準(zhǔn)備好了一切,composer是php的未來,沒有composer,php肯定要走向沒落

laravel框架最大的特點(diǎn)和優(yōu)秀之處就是集合了php比較新的特點(diǎn),以及各種各樣的設(shè)計(jì)模式,Ioc模式,依賴注入等

14.laravel有那些特點(diǎn)?

回答一:

1.強(qiáng)大的rest router:用簡單的回調(diào)函數(shù)就可以調(diào)用,快速綁定controller和router
2.artisan:命令行工具,很多手動(dòng)的工作都自動(dòng)化
3.可繼承的模板,簡化view的開發(fā)和管理
4.blade模板:渲染速度更快
5.ORM操作數(shù)據(jù)庫
6.migration:管理數(shù)據(jù)庫和版本控制
7.測試功能也很強(qiáng)大
8.composer也是亮點(diǎn)

回答二: laravel框架引入了門面,依賴注入,Ioc模式,以及各種各樣的設(shè)計(jì)模式等

15.請簡述一下數(shù)據(jù)庫的優(yōu)化?

答:數(shù)據(jù)庫的優(yōu)化可以從四個(gè)方面來優(yōu)化:

1.從結(jié)構(gòu)層: web服務(wù)器采用負(fù)載均衡服務(wù)器,mysql服務(wù)器采用主從復(fù)制,讀寫分離
2.從儲存層: 采用合適的存儲引擎,采用三范式
3.從設(shè)計(jì)層: 采用分區(qū)分表,索引,表的字段采用合適的字段屬性,適當(dāng)?shù)牟捎媚娣妒?開啟mysql緩存
4.sql語句層:結(jié)果一樣的情況下,采用效率高,速度快節(jié)省資源的sql語句執(zhí)行

16.如何解決異常處理?

答: 拋出異常:使用try…catch,異常的代碼放在try代碼塊內(nèi),如果沒有觸發(fā)異常,則代碼繼續(xù)執(zhí)行,如果異常被觸發(fā),就會(huì) 拋出一個(gè)異常。Catch代碼塊捕獲異常,并創(chuàng)建一個(gè)包含異常信息的對象。$e->getMessage(),輸出異常的錯(cuò)誤信息。

解決異常:使用set_error_handler函數(shù)獲取異常(也可以使用try()和catch()函數(shù)),然后使用set_exception_handler()函數(shù)設(shè)置默認(rèn)的異常處理程序,register_shutdown_function()函數(shù)來執(zhí)行,執(zhí)行機(jī)制是,php要把調(diào)入的函數(shù)調(diào)入到內(nèi)存,當(dāng)頁面所有的php語句都執(zhí)行完成時(shí),再調(diào)用此函數(shù)

17.前端?

答:我在工作中處理前端的功能,一般就是用ajax向后臺請求數(shù)據(jù),然后返回?cái)?shù)據(jù)在前臺頁面中顯示出來。我從來沒有獨(dú)立的完整的將html和css樣式都一個(gè)人完成,如果公司實(shí)在有這樣的需求的話,我可能會(huì)找一些前臺的模板或者說是前端的框架,比如說h—ui等等

18.權(quán)限管理(RBAC)的實(shí)現(xiàn)?

1.首先創(chuàng)建一張用戶表:id name auto(保存格式為:控制器-方法)

2.然后在后臺中創(chuàng)建一個(gè)基類控制器,控制器里封裝一個(gè)構(gòu)造方法,當(dāng)用戶登陸成功后,使用TP框架中封裝好的session函數(shù)獲取保存在服務(wù)器中的session id,然后實(shí)例化模型,通過用戶id獲取保存在數(shù)據(jù)表中的auth數(shù)據(jù),使用explode函數(shù)分割獲取到的數(shù)據(jù),并使用一個(gè)數(shù)組保存起來,然后使用TP框架中封裝好的常量獲取當(dāng)前控制器和方法,然后把他們組裝成字符串,使用in_array函數(shù)進(jìn)行判斷該數(shù)組中是否含有當(dāng)前獲取到的控制器和方法,如果沒有,就提示該用戶沒有權(quán)限,如果有就進(jìn)行下一步操作

19.支付功能的實(shí)現(xiàn)?

答:

20.怎么保證促銷商品不會(huì)超賣?

答:這個(gè)問題是我們當(dāng)時(shí)開發(fā)時(shí)遇到的一個(gè)難點(diǎn),超賣的原因主要是下的訂單的數(shù)目和我們要促銷的商品的數(shù)目不一致導(dǎo)致的,每次總是訂單的數(shù)比我們的促銷商品的數(shù)目要多,當(dāng)時(shí)我們的小組討論了好久,給出了好幾個(gè)方案來實(shí)現(xiàn):

第一種方案:在每次下訂單前我們判斷促銷商品的數(shù)量夠不夠,不夠不允許下訂單,更改庫存量時(shí)加上一個(gè)條件,只更改商品庫存大于0的商品的庫存,當(dāng)時(shí)我們使用ab進(jìn)行壓力測試,當(dāng)并發(fā)超過500,訪問量超過2000時(shí),還是會(huì)出現(xiàn)超賣現(xiàn)象。所以被我們否定了。

第二種方案:使用mysql的事務(wù)加排他鎖來解決,首先我們選擇數(shù)據(jù)庫的存儲引擎為innoDB,使用的是排他鎖實(shí)現(xiàn)的,剛開始的時(shí)候我們測試了下共享鎖,發(fā)現(xiàn)還是會(huì)出現(xiàn)超賣的現(xiàn)象。有個(gè)問題是,當(dāng)我們進(jìn)行高并發(fā)測試時(shí),對數(shù)據(jù)庫的性能影響很大,導(dǎo)致數(shù)據(jù)庫的壓力很大,最終也被我們否定了。

第三種方案:使用文件鎖實(shí)現(xiàn)。當(dāng)用戶搶到一件促銷商品后先觸發(fā)文件鎖,防止其他用戶進(jìn)入,該用戶搶到促銷品后再解開文件鎖,放其他用戶進(jìn)行操作。這樣可以解決超賣的問題,但是會(huì)導(dǎo)致文件得I/O開銷很大。

最后我們使用了redis的隊(duì)列來實(shí)現(xiàn)。將要促銷的商品數(shù)量以隊(duì)列的方式存入redis中,每當(dāng)用戶搶到一件促銷商品則從隊(duì)列中刪除一個(gè)數(shù)據(jù),確保商品不會(huì)超賣。這個(gè)操作起來很方便,而且效率極高,最終我們采取這種方式來實(shí)現(xiàn)

21.商城秒殺的實(shí)現(xiàn)?

答:搶購、秒殺是如今很常見的一個(gè)應(yīng)用場景,主要需要解決的問題有兩個(gè):

1 高并發(fā)對數(shù)據(jù)庫產(chǎn)生的壓力
2 競爭狀態(tài)下如何解決庫存的正確減少("超賣"問題)

對于第一個(gè)問題,已經(jīng)很容易想到用緩存來處理搶購,避免直接操作數(shù)據(jù)庫,例如使用Redis。第二個(gè)問題,我們可以使用redis隊(duì)列來完成,把要秒殺的商品放入到隊(duì)列中,因?yàn)閜op操作是原子的,即使有很多用戶同時(shí)到達(dá),也是依次執(zhí)行,文件鎖和事務(wù)在高并發(fā)下性能下降很快,當(dāng)然還要考慮其他方面的東西,比如搶購頁面做成靜態(tài)的,通過ajax調(diào)用接口,其中也可能會(huì)出現(xiàn)一個(gè)用戶搶多次的情況,這時(shí)候需要再加上一個(gè)排隊(duì)隊(duì)列和搶購結(jié)果隊(duì)列及庫存隊(duì)列。高并發(fā)情況下,將用戶進(jìn)入排隊(duì)隊(duì)列,用一個(gè)線程循環(huán)處理從排隊(duì)隊(duì)列取出一個(gè)用戶,判斷用戶是否已在搶購結(jié)果隊(duì)列,如果在,則已搶購,否則未搶購,庫存減1,寫數(shù)據(jù)庫,將用戶入結(jié)果隊(duì)列。

22.購物車的原理?

答:購物車相當(dāng)于現(xiàn)實(shí)中超市的購物車,不同的是一個(gè)是實(shí)體車,一個(gè)是虛擬車而已。用戶可以在購物網(wǎng)站的不同頁面之間跳轉(zhuǎn),以選購自己喜愛的商品,點(diǎn)擊購買時(shí),該商品就自動(dòng)保存到你的購物車中,重復(fù)選購后,最后將選中的所有商品放在購物車中統(tǒng)一到付款臺結(jié)賬,這也是盡量讓客戶體驗(yàn)到現(xiàn)實(shí)生活中購物的感覺。服務(wù)器通過追蹤每個(gè)用戶的行動(dòng),以保證在結(jié)賬時(shí)每件商品都物有其主。

主要涉及以下幾點(diǎn):

    1、把商品添加到購物車,即訂購
    2、刪除購物車中已定購的商品
    3、修改購物車中某一本圖書的訂購數(shù)量
    4、清空購物車
    5、顯示購物車中商品清單及數(shù)量、價(jià)格

實(shí)現(xiàn)購物車的關(guān)鍵在于服務(wù)器識別每一個(gè)用戶并維持與他們的聯(lián)系。但是HTTP協(xié)議是一種“無狀態(tài)(Stateless)”的協(xié)議,因而服務(wù)器不能記住是誰在購買商品,當(dāng)把商品加入購物車時(shí),服務(wù)器也不知道購物車?yán)镌扔行┦裁矗沟糜脩粼诓煌撁骈g跳轉(zhuǎn)時(shí)購物車無法“隨身攜帶”,這都給購物車的實(shí)現(xiàn)造成了一定的困難。

目前購物車的實(shí)現(xiàn)主要是通過cookie、session或結(jié)合數(shù)據(jù)庫的方式。下面分析一下它們的機(jī)制及作用。

cookie

cookie是由服務(wù)器產(chǎn)生,存儲在客戶端的一段信息。它定義了一種Web服務(wù)器在客戶端存儲和返回信息的機(jī)制,cookie文件它包含域、路徑、生存期、和由服務(wù)器設(shè)置的變量值等內(nèi)容。當(dāng)用戶以后訪問同一個(gè)Web服務(wù)器時(shí),瀏覽器會(huì)把cookie原樣發(fā)送給服務(wù)器。通過讓服務(wù)器讀取原先保存到客戶端的信息,網(wǎng)站能夠?yàn)闉g覽者提供一系列的方便,例如在線交易過程中標(biāo)識用戶身份、安全要求不高的場合避免用戶重復(fù)輸入名字和密碼、門戶網(wǎng)站的主頁定制、有針對性地投放廣告等等。利用cookie的特性,大大擴(kuò)展了WEB應(yīng)用程序的功能,不僅可以建立服務(wù)器與客戶機(jī)的聯(lián)系,因?yàn)閏ookie可以由服務(wù)器定制,因此還可以將購物信息生成cookie值存放在客戶端,從而實(shí)現(xiàn)購物車的功能。用基于cookie的方式實(shí)現(xiàn)服務(wù)器與瀏覽器之間的會(huì)話或購物車,有以下特點(diǎn):

1、cookie存儲在客戶端,且占用很少的資源,瀏覽器允許存放300個(gè)cookie,每個(gè)cookie的大小為4KB,足以滿足購物車的要求,同時(shí)也減輕了服務(wù)器的負(fù)荷;
2、cookie為瀏覽器所內(nèi)置,使用方便。即使用戶不小心關(guān)閉了瀏覽器窗口,只要在cookie定義的有效期內(nèi),購物車中的信息也不會(huì)丟失;
3、cookie不是可執(zhí)行文件,所以不會(huì)以任何方式執(zhí)行,因此也不會(huì)帶來病毒或攻擊用戶的系統(tǒng);
4、基于cookie的購物車要求用戶瀏覽器必須支持并設(shè)置為啟用cookie,否則購物車則失效;
5、存在著關(guān)于cookie侵犯訪問者隱私權(quán)的爭論,因此有些用戶會(huì)禁止本機(jī)的cookie功能。

session

session是實(shí)現(xiàn)購物車的另一種方法。session提供了可以保存和跟蹤用戶的狀態(tài)信息的功能,使當(dāng)前用戶在session中定義的變量和對象能在頁面之間共享,但是不能為應(yīng)用中其他用戶所訪問,它與cookie最重大的區(qū)別是,session將用戶在會(huì)話期間的私有信息存儲在服務(wù)器端,提高了安全性。在服務(wù)器生成session后,客戶端會(huì)生成一個(gè)sessionid識別號保存在客戶端,以保持和服務(wù)器的同步。這個(gè)sessionid是只讀的,如果客戶端禁止cookie功能,session會(huì)通過在URL中附加參數(shù),或隱含在表單中提交等其他方式在頁面間傳送。因此利用session實(shí)施對用戶的管理則更為安全、有效。

同樣,利用session也能實(shí)現(xiàn)購物車,這種方式的特點(diǎn)是:

1、session用新的機(jī)制保持與客戶端的同步,不依賴于客戶端設(shè)置;
2、與cookie相比,session是存儲在服務(wù)器端的信息,因此顯得更為安全,因此可將身份標(biāo)示,購物等信息存儲在session中;
3、session會(huì)占用服務(wù)器資源,加大服務(wù)器端的負(fù)載,尤其當(dāng)并發(fā)用戶很多時(shí),會(huì)生成大量的session,影響服務(wù)器的性能;
4、因?yàn)閟ession存儲的信息更敏感,而且是以文件形式保存在服務(wù)器中,因此仍然存在著安全隱患。

結(jié)合數(shù)據(jù)庫的方式

這也是目前較普遍的模式,在這種方式中,數(shù)據(jù)庫承擔(dān)著存儲購物信息的作用,session或cookie則用來跟蹤用戶。這種方式具有以下特點(diǎn):

1、數(shù)據(jù)庫與cookie分別負(fù)責(zé)記錄數(shù)據(jù)和維持會(huì)話,能發(fā)揮各自的優(yōu)勢,使安全性和服務(wù)器性能都得到了提高;
2、每一個(gè)購物的行為,都要直接建立與數(shù)據(jù)庫的連接,直至對表的操作完成后,連接才釋放。當(dāng)并發(fā)用戶很多時(shí),會(huì)影響數(shù)據(jù)庫的性能,因此,這對數(shù)據(jù)庫的性能提出了更高的要求;
3、使cookie維持會(huì)話有賴客戶端的支持。

各種方式的選擇:

雖然cookie可用來實(shí)現(xiàn)購物車,但必須獲得瀏覽器的支持,再加上它是存儲在客戶端的信息,極易被獲取,所以這也限制了它存儲更多,更重要的信息。所以一般cookie只用來維持與服務(wù)器的會(huì)話,例如國內(nèi)最大的當(dāng)當(dāng)網(wǎng)絡(luò)書店就是用cookie保持與客戶的聯(lián)系,但是這種方式最大的缺點(diǎn)是如果客戶端不支持cookie就會(huì)使購物車失效。

Session能很好地與交易雙方保持會(huì)話,可以忽視客戶端的設(shè)置。在購物車技術(shù)中得到了廣泛的應(yīng)用。但session的文件屬性使其仍然留有安全隱患。

結(jié)合數(shù)據(jù)庫的方式雖然在一定程度上解決了上述的問題,但從上面的例子可以看出:在這種購物流程中涉及到對數(shù)據(jù)庫表的頻繁操作,尤其是用戶每選購一次商品,都要與數(shù)據(jù)庫進(jìn)行連接,當(dāng)用戶很多的時(shí)候就加大了服務(wù)器與數(shù)據(jù)庫的負(fù)荷。

23.redis消息隊(duì)列先進(jìn)先出需要注意什么?

答:通常使用一個(gè)list來實(shí)現(xiàn)隊(duì)列操作,這樣有一個(gè)小限制,所以的任務(wù)統(tǒng)一都是先進(jìn)先出,如果想優(yōu)先處理某個(gè)任務(wù)就不太好處理了,這就需要讓隊(duì)列有優(yōu)先級的概念,我們就可以優(yōu)先處理高級別的任務(wù),實(shí)現(xiàn)方式有以下幾種方式:

1)單一列表實(shí)現(xiàn):隊(duì)列正常的操作是 左進(jìn)右出(lpush,rpop)為了先處理高優(yōu)先級任務(wù),在遇到高級別任務(wù)時(shí),可以直接插隊(duì),直接放入隊(duì)列頭部(rpush),這樣,從隊(duì)列頭部(右側(cè))獲取任務(wù)時(shí),取到的就是高優(yōu)先級的任務(wù)(rpop)

2)使用兩個(gè)隊(duì)列,一個(gè)普通隊(duì)列,一個(gè)高級隊(duì)列,針對任務(wù)的級別放入不同的隊(duì)列,獲取任務(wù)時(shí)也很簡單,redis的BRPOP命令可以按順序從多個(gè)隊(duì)列中取值,BRPOP會(huì)按照給出的 key 順序查看,并在找到的第一個(gè)非空 list 的尾部彈出一個(gè)元素,redis> BRPOP list1 list2 0

list1 做為高優(yōu)先級任務(wù)隊(duì)列
list2 做為普通任務(wù)隊(duì)列

這樣就實(shí)現(xiàn)了先處理高優(yōu)先級任務(wù),當(dāng)沒有高優(yōu)先級任務(wù)時(shí),就去獲取普通任務(wù)

方式1最簡單,但實(shí)際應(yīng)用比較局限,方式3可以實(shí)現(xiàn)復(fù)雜優(yōu)先級,但實(shí)現(xiàn)比較復(fù)雜,不利于維護(hù)

方式2是推薦用法,實(shí)際應(yīng)用最為合適

24.你負(fù)責(zé)的模塊有哪些難題?

答:在我負(fù)責(zé)的B2B電商項(xiàng)目中,當(dāng)時(shí)我負(fù)責(zé)的是訂單模塊,由于客戶一次選擇了多家商戶的商品,最終生成了一個(gè)訂單,這樣我們平臺在給商戶結(jié)算時(shí)出現(xiàn)了不知道這比費(fèi)用應(yīng)該給哪個(gè)商戶,這時(shí)候我們小組經(jīng)過討論,需要涉及到訂單拆分,也就是說用戶點(diǎn)擊支付后,如果有多件商品,并且不是同一家店鋪那么 就要用到訂單的拆分,比如如果有兩件商品,并且不是同一店鋪 就在原來的訂單號下 在生成兩個(gè)子訂單號 并修改訂單表中兩件商品的訂單號。最終實(shí)現(xiàn)了商品的分配管理,解決了我們的難題。

我覺得在開發(fā)過程中,遇到的難題無非是兩個(gè),一個(gè)是技術(shù)層次的,我認(rèn)為,只要你有恒心,有熱心,沒有覺得不了的難題。另一個(gè)就是溝通問題,在任何地方任何時(shí)候溝通都是最重要的,尤其是我們做開發(fā)的,不溝通好,會(huì)影響整個(gè)項(xiàng)目的進(jìn)度,我本人是個(gè)非常還溝通的人,所以這點(diǎn)上也沒多大問題。

25.用戶下單是怎么處理的?

答:判斷用戶有沒有登錄,在沒有登錄的情況下,不允許下單。登陸后,可進(jìn)行下單,并生成唯一的訂單號,此時(shí)訂單的狀態(tài)為未支付。

26.電商的登錄是怎么實(shí)現(xiàn)的?

答:分為普通登錄和第三方登錄 這邊主要說一下第三方登錄吧,第三方登陸主要使用的是author協(xié)議,我就以QQ的第三方登陸為例來進(jìn)行說明:當(dāng)用戶在我們的站點(diǎn)請求QQ的第三方登陸時(shí),我們站點(diǎn)會(huì)引導(dǎo)用戶跳轉(zhuǎn)到QQ的登陸授權(quán)界面, 當(dāng)用戶輸入QQ和密碼成功登錄以后會(huì)自動(dòng)跳回到我們站點(diǎn)設(shè)置好的回調(diào)頁面,并附帶一個(gè)code參數(shù),接著你使用code再次去請求QQ的授權(quán)頁面,就可以從中獲取到一個(gè)access token(訪問令牌),通過這個(gè)access_token,我們可以調(diào)用QQ提供給我們的接口,比如獲取open_id,可以獲取用戶的基本信息。獲取到之后,我們需要拿用戶的授權(quán)信息和open_id和我們平臺的普通用戶進(jìn)行綁定。這樣不管是普通用戶登陸還是第三方登陸用戶,都可以實(shí)現(xiàn)登陸。

27.接口安全方面是怎么處理的?

答:我們當(dāng)時(shí)是這么做的,使用HTTP的POST方式,對固定參數(shù)+附加參數(shù)進(jìn)行數(shù)字簽名,使用的是md5加密,比如:我想通過標(biāo)題獲取一個(gè)信息,在客戶端使用 信息標(biāo)題+日期+雙方約定好的一個(gè)key通過md5加密生成一個(gè)簽名(sign),然后作為參數(shù)傳遞到服務(wù)器端,服務(wù)器端使用同樣的方法進(jìn)行校驗(yàn),如何接受過來的sign和我們通過算法算的值相同,證明是一個(gè)正常的接口請求,我們才會(huì)返回相應(yīng)的接口數(shù)據(jù)。

28.用的什么技術(shù)實(shí)現(xiàn)短信發(fā)送,在哪調(diào)用?

答:我主要用的第三方短信接口,在申請接口時(shí)進(jìn)行相應(yīng)信息的配置,然后在我們站點(diǎn)需要用到短信驗(yàn)證的地方進(jìn)行調(diào)用,我們通常在用戶注冊時(shí)使用到。

29.在工作中遇到什么困難?

答:總體來說:在工作我主要遇到這幾個(gè)問題比較難處理:

① When I was working before, I found that there were often some temporary needs that disrupted my plans. Sometimes the task was not completed yet, and I had to do other tasks. At the end of the day, everything big and small There are many, but they are not completed very well. I will summarize them later. I will add priorities to these. When encountering temporary needs, I will re-arrange existing tasks and temporary tasks according to priority to ensure that they are within the specified time. Complete high-priority tasks efficiently.

②When working on project requirements, if you encounter people with poor understanding ability, you will easily get angry when communicating, which will affect your emotions. In the end, you will not be able to achieve the required results. From now on, whenever this happens, I will usually use something paper-based and more visual to communicate in a way that both parties can agree on and understand, which will reduce a lot of unnecessary trouble in the future. Everyone knows that for programmers, changing requirements is a very painful thing, so early communication is very important.

③One more thing, my previous leader didn’t know much about technology, so every time a new requirement came out, we were always required to complete it within a short period of time. If we couldn’t complete it, we would be fired. There is doubt about ability. Of course, every leader hopes that his employees can complete tasks as quickly as possible, reduce costs, and improve efficiency. At this time, I will refine our needs, list the key points and difficulties, make time plans, and patiently communicate with the leaders about the importance of each point of the project and the proportion of time spent, to ensure that in this plan Complete the task with quality and quantity within the time point. Gradually, I gained recognition from the leadership. In fact, the leadership is not blindly unreasonable. As long as things are planned well and the highest value is obtained at the lowest cost, everyone can easily understand.

30. How can the user directly add to the shopping cart without logging in?

Answer: The user can add the information of the product to be purchased (such as product ID, product price) without logging in. , product's sku_id, purchase quantity and other key data) are stored in COOKIE when logging in. Save the contents of the COOKIE to the database and clear the data in the cookie.

31. Have you ever written an interface? How do you define an interface?

Answer: Yes. There are two types of interfaces: one is the data interface and the other is the application interface.

Data type interface: It is a certain "structure" that is more abstract than an abstract class - it is not actually a class, but a certain grammatical structure like a class, which is a structural specification. , standardizing the format in which our classes should be defined. It is generally used when the team is relatively large and there are many branches.

Application interface: API (application interface) is an entrance for external access to data

I am mainly involved in the writing of interfaces in APP development. What does the client need? We will provide them with the corresponding data. The data will be returned in json/xml format and accompanied by corresponding interface documents.

32.Sku reduction inventory?

Answer: SKU = Stock Keeping Unit (stock keeping unit)

That is, the unit for measuring inventory in and out, you can It is based on pieces, boxes, pallets, etc. SKU is a stock keeping unit that distinguishes single products.

is most commonly used in clothing and footwear products. For example, a SKU in textiles usually represents: specifications, colors, and styles.

When designing the table, there is not only a product table, but also a total inventory in the product table. We also need to involve a SKU table, which has SKU inventory and unit price fields. Every time a user purchases a product, the actual All products purchased online are SKU products, so after the order is successfully placed, the corresponding SKU inventory should be reduced based on the unique SKU number of the purchased product. Of course, the total inventory of the products is stored in the product master table, and the total inventory also needs to be reduced. The amount of stock in inventory.

33. Inventory settings?

Answer: Inventory is divided into total merchandise inventory and SKU inventory. Often the total merchandise inventory is the sum of SKU inventories. Generally, after the maximum inventory and minimum inventory are set for the goods in the backend of the mall, the current inventory quantity is compared with the maximum and minimum. If the inventory exceeds or is lower than the inventory, it will be reflected in the form of a report to facilitate users to grasp the inventory overflow and shortage of goods. Status and quantity.

34. How to ensure the consistency of data in the order and inventory tables?

Answer: In an e-commerce system, it is normal that after the order is successfully generated, the corresponding inventory reduction must ensure the consistency of the two, but sometimes due to some reasons, such as Program logic problems, concurrency and other issues lead to successful orders but no reduction in inventory. We do not allow this situation to happen. The transaction in MySQL can just solve this problem. First, you must choose the storage engine of the database to be InnoDB. The transaction stipulates that it is only allowed when the order is placed and the corresponding inventory is reduced. Commit the transaction, otherwise the transaction will be rolled back to ensure data consistency.

35.O2O users place orders on the c-side. How to ensure that the data on the ba-side is consistent?

答:O2O為線上和線下模式,O2O模式奉行的是“線上支付+實(shí)體店消費(fèi)”的消費(fèi)模式,即消費(fèi)者在網(wǎng)上下單完成支付后,憑消費(fèi)憑證到實(shí)體店消費(fèi)。 O2O模式是把商家信息和支付程序放在線上進(jìn)行,而把商品和服務(wù)兌現(xiàn)放在線下,也就是說O2O模式適用于快遞無法送達(dá)的有形產(chǎn)品。數(shù)據(jù)一致性的問題是O2O行業(yè)中最常見的問題,我們可以類似于數(shù)據(jù)庫的主從復(fù)制的思路來解決這個(gè)問題.O2O有個(gè)供應(yīng)商系統(tǒng),類似于主服務(wù)器,在?端(從服務(wù)器)下單時(shí),數(shù)據(jù)同步更新到供應(yīng)商系統(tǒng)端,b,a實(shí)時(shí)從供應(yīng)商系統(tǒng)中拉取數(shù)據(jù)進(jìn)行同步,比如利用定時(shí)任務(wù),定時(shí)拉取數(shù)據(jù)進(jìn)行同步。

36.Redis如何防止高并發(fā)?

答:其實(shí)redis是不會(huì)存在并發(fā)問題的,因?yàn)樗菃芜M(jìn)程的,再多的命令都是一個(gè)接一個(gè)地執(zhí)行的。我們使用的時(shí)候,可能會(huì)出現(xiàn)并發(fā)問題,比如獲得和設(shè)定這一對。Redis的為什么 有高并發(fā)問題?Redis的的出身決定

Redis是一種單線程機(jī)制的nosql數(shù)據(jù)庫,基于key-value,數(shù)據(jù)可持久化落盤。由于單線程所以redis本身并沒有鎖的概念,多個(gè)客戶端連接并不存在競爭關(guān)系,但是利用jedis等客戶端對redis進(jìn)行并發(fā)訪問時(shí)會(huì)出現(xiàn)問題。發(fā)生連接超時(shí)、數(shù)據(jù)轉(zhuǎn)換錯(cuò)誤、阻塞、客戶端關(guān)閉連接等問題,這些問題均是由于客戶端連接混亂造成。

同時(shí),單線程的天性決定,高并發(fā)對同一個(gè)鍵的操作會(huì)排隊(duì)處理,如果并發(fā)量很大,可能造成后來的請求超時(shí)。

在遠(yuǎn)程訪問redis的時(shí)候,因?yàn)榫W(wǎng)絡(luò)等原因造成高并發(fā)訪問延遲返回的問題。

解決辦法

在客戶端將連接進(jìn)行池化,同時(shí)對客戶端讀寫Redis操作采用內(nèi)部鎖synchronized。

服務(wù)器角度,利用setnx變向?qū)崿F(xiàn)鎖機(jī)制。

37.秒殺當(dāng)中的細(xì)節(jié)你是怎么得出來的?

答:通過性能測試及模擬秒殺場景。每個(gè)問題都經(jīng)過反復(fù)測試,不斷的發(fā)現(xiàn)問題,不斷的解決。

38.做秒殺用什么數(shù)據(jù)庫,怎么實(shí)現(xiàn)的?

答:因?yàn)槊霘⒌囊凰查g,并發(fā)非常大,如果同時(shí)請求數(shù)據(jù)庫,會(huì)導(dǎo)致數(shù)據(jù)庫的壓力非常大,導(dǎo)致數(shù)據(jù)庫的性能急劇下降,更嚴(yán)重的可能會(huì)導(dǎo)致數(shù)據(jù)庫服務(wù)器宕機(jī)。這時(shí)候一般采用內(nèi)存高速緩存數(shù)據(jù)庫redis來實(shí)現(xiàn)的,redis是非關(guān)系型數(shù)據(jù)庫,redis是單線程的,通過redis的隊(duì)列可以完成秒殺過程。

39.支付寶流程怎么實(shí)現(xiàn)的?

答:首先要有一個(gè)支付寶賬號,接下來向支付寶申請?jiān)诰€支付業(yè)務(wù),簽署協(xié)議。協(xié)議生效后有支付寶一方會(huì)給網(wǎng)站方一個(gè)合作伙伴ID,和安全校驗(yàn)碼,有了這兩樣?xùn)|西就可以按照支付寶接口文檔開發(fā)支付寶接口了,中間主要涉及到一個(gè)安全問題。整個(gè)流程是這樣的:我們的網(wǎng)站通過post傳遞相應(yīng)的參數(shù)(如訂單總金額,訂單號)到支付頁面,支付頁面把一系列的參數(shù)經(jīng)過處理,以post的方式提交給支付寶服務(wù)器,支付寶服務(wù)器進(jìn)行驗(yàn)證,并對接收的數(shù)據(jù)進(jìn)行處理,把處理后的結(jié)果返回給我們網(wǎng)站設(shè)置的異步和同步回調(diào)地址,通過相應(yīng)的返回參數(shù),來處理相應(yīng)的業(yè)務(wù)邏輯,比如返回的參數(shù)代表支付成功,更改訂單狀態(tài)。

40.什么是單點(diǎn)登錄?

答:單點(diǎn)登錄SSO(Single Sign On)說得簡單點(diǎn)就是在一個(gè)多系統(tǒng)共存的環(huán)境下,用戶在一處登錄后,就不用在其他系統(tǒng)中登錄,也就是用戶的一次登錄能得到其他所有系統(tǒng)的信任。

41.什么情況下使用緩存?

答:當(dāng)用戶第一次訪問應(yīng)用系統(tǒng)的時(shí)候,因?yàn)檫€沒有登錄,會(huì)被引導(dǎo)到認(rèn)證系統(tǒng)中進(jìn)行登錄;根據(jù)用戶提供的登錄信息,認(rèn)證系統(tǒng)進(jìn)行身份校驗(yàn),如果通過校驗(yàn),應(yīng)該返回給用戶一個(gè)認(rèn)證的憑據(jù)--ticket;用戶再訪問別的應(yīng)用的時(shí)候,就會(huì)將這個(gè)ticket帶上,作為自己認(rèn)證的憑據(jù),應(yīng)用系統(tǒng)接受到請求之后會(huì)把 ticket送到認(rèn)證系統(tǒng)進(jìn)行校驗(yàn),檢查ticket的合法性。如果通過校驗(yàn),用戶就可以在不用再次登錄的情況下訪問應(yīng)用系統(tǒng)2和應(yīng)用系統(tǒng)3了。

實(shí)現(xiàn)主要技術(shù)點(diǎn):

    1、兩個(gè)站點(diǎn)共用一個(gè)數(shù)據(jù)驗(yàn)證系統(tǒng)
    2、主要通過跨域請求的方式來實(shí)現(xiàn)驗(yàn)證及session處理。

42.怎么實(shí)現(xiàn)第三方登錄?

答:第三方登陸主要是基于author協(xié)議來實(shí)現(xiàn),下面簡單說下實(shí)現(xiàn)流程:

1、首先我們需要以開發(fā)者的身份向第三方登陸平臺申請接入應(yīng)用,申請成功后,我們會(huì)獲得一個(gè)appID和一個(gè)secrectID.
2、當(dāng)我們的網(wǎng)站需接入第三方登陸時(shí),會(huì)引導(dǎo)用戶跳轉(zhuǎn)到第三方的登陸授權(quán)頁面,此時(shí)把之前申請的appID和secrectID帶給登陸授權(quán)頁面。
3、用戶登陸成功后即得到授權(quán),第三方會(huì)返回一個(gè)臨時(shí)的code給我們的網(wǎng)站。
4、我們的網(wǎng)站接受到code后,再次向我們的第三方發(fā)起請求,并攜帶接收的code,從第三方獲取access_token.
5、第三方處理請求后,會(huì)返回一個(gè)access_token給我們的網(wǎng)站,我們的網(wǎng)站獲取到access_token后就可以調(diào)用第三方提供的接口了,比如獲取用戶信息等。最后把該用戶信息存入到我們站點(diǎn)的數(shù)據(jù)庫,并把信息保存到session中,實(shí)現(xiàn)用戶的第三方登陸。

43.如何處理負(fù)載、高并發(fā)?(好好看看,經(jīng)常問到,能回答到主要的東西即可)?

答:從低成本、高性能和高擴(kuò)張性的角度來說有如下處理方案:

1、HTML靜態(tài)化

In fact, everyone knows that the most efficient and least consumed is a purely static html page, so we try our best to use static pages for the pages on our website. This simplest method is actually the most effective method. .

2. Separate picture servers

Store pictures separately to minimize the overhead of large traffic such as pictures. You can place them on some related platforms, such as bull riding, etc.

3. Database cluster and database table hashing and caching

The concurrent connections of the database are 100. One database is far from enough. You can start from the aspects of read-write separation, master-slave replication, and database cluster. In addition, to minimize database access, you can use cache databases such as memcache and redis.

4. Mirror:

Reduce downloads as much as possible and distribute different requests to multiple mirrors.

5. Load balancing:

The maximum concurrent connections of Apache is 1500. You can only add servers. You can start with hardware, such as F5 server. Of course, the cost of hardware is relatively high, so we often start from the software side.

Load Balancing is built on the existing network structure. It provides a cheap, effective and transparent method to expand the bandwidth of network devices and servers, increase throughput, and enhance network data processing capabilities. Can improve network flexibility and availability. Currently, the most widely used load balancing software is Nginx, LVS, and HAProxy. Let me talk about the advantages and disadvantages of the three types respectively:

The advantages of Nginx are:

It works above the 7th layer of the network and can do some diversion for http applications. Strategies, such as domain name and directory structure, its regular rules are more powerful and flexible than HAProxy, which is one of the main reasons why it is currently widely popular. Nginx can be exploited in far more situations than LVS based on this alone.

Nginx relies very little on network stability. In theory, it can perform load functions if it can be pinged. This is also one of its advantages; on the contrary, LVS relies heavily on network stability, which I deeply understand. I have experience;

Nginx is relatively simple to install and configure, and it is more convenient to test. It can basically print out errors in the log. The configuration and testing of LVS takes a relatively long time, and LVS relies heavily on the network.

It can withstand high load pressure and is stable. If the hardware is not bad, it can generally support tens of thousands of concurrency, and the load degree is relatively smaller than LVS.

Nginx can detect internal server failures through the port, such as status codes, timeouts, etc. returned by the server processing web pages, and will resubmit requests that return errors to another node. However, the disadvantage is that it cannot Support url to detect. For example, if the user is uploading a file, and the node processing the upload fails during the upload process, Nginx will switch the upload to another server for reprocessing, and LVS will be directly disconnected. If a large file is uploaded, Or very important files, users may be dissatisfied.

Nginx is not only an excellent load balancer/reverse proxy software, it is also a powerful web application server. LNMP is also a very popular web architecture in recent years, and its stability is also very good in high-traffic environments.

Nginx is now becoming more and more mature as a Web reverse acceleration cache and is faster than the traditional Squid server. You can consider using it as a reverse proxy accelerator.

Nginx can be used as a mid-level reverse proxy. At this level, Nginx basically has no rivals. The only one that can compare with Nginx is lighttpd. However, lighttpd does not yet have the full functions of Nginx, and the configuration is not so good. It is clear and easy to read, and the community information is far less active than Nginx.

Nginx can also be used as a static web page and image server, and its performance in this area is unmatched. The Nginx community is also very active and there are many third-party modules.

The disadvantages of Nginx are:

Nginx can only support http, https and Email protocols, so the scope of application is smaller. This is its shortcoming.

The health check of the back-end server only supports detection through the port and does not support detection through the URL. Direct retention of Session is not supported, but it can be solved through ip_hash.

LVS: Use Linux kernel cluster to implement a high-performance, high-availability load balancing server, which has good scalability (Scalability), reliability (Reliability) and manageability (Manageability).

The advantages of LVS are:

It has strong load resistance and works above the 4th layer of the network for distribution only. There is no traffic generation. This feature also This determines its strongest performance among load balancing software and its relatively low consumption of memory and CPU resources.

The configurability is relatively low, which is a disadvantage and an advantage. Because there is nothing that can be configured too much, it does not require too much contact, which greatly reduces the chance of human error.

It works stably because it has strong load resistance and has a complete dual-machine hot backup solution, such as LVS Keepalived. However, the one we use most in project implementation is LVS/DR Keepalived.

No traffic, LVS only distributes requests, and traffic does not go out from itself. This ensures that the performance of the balancer IO will not be affected by large traffic.

The application range is relatively wide. Because LVS works on layer 4, it can load balance almost all applications, including http, databases, online chat rooms, etc.

The disadvantages of LVS are:

The software itself does not support regular expression processing and cannot separate dynamic and static; and many websites now have strong needs in this regard , this is the advantage of Nginx/HAProxy Keepalived.

If the website application is relatively large, LVS/DR Keepalived will be more complicated to implement. Especially if there is a Windows Server machine behind it, the implementation, configuration and maintenance process will be more complicated. Relatively speaking, , Nginx/HAProxy Keepalived is much simpler.

The characteristics of HAProxy are:

HAProxy also supports virtual hosts.

The advantages of HAProxy can supplement some of the shortcomings of Nginx, such as supporting Session retention and Cookie guidance; it also supports detecting the status of the back-end server by obtaining the specified URL.

HAProxy is similar to LVS, it is just a load balancing software; purely in terms of efficiency, HAProxy will have better load balancing speed than Nginx, and it is also better than Nginx in concurrent processing.

HAProxy supports load balancing forwarding of the TCP protocol. It can load balance MySQL reads and detect and load balance the back-end MySQL nodes. You can use LVS Keepalived to load balance the MySQL master and slave.

There are many HAProxy load balancing strategies. HAProxy's load balancing algorithms currently have the following eight types:

① roundrobin, which means simple polling. I won't say much about this. This is the basics of load balancing. All have;

② static-rr, indicating that based on the weight, it is recommended to pay attention;

③ leastconn, indicating that the least connected ones are processed first, it is recommended to pay attention;

④ source, Indicates based on the request source IP. This is similar to Nginx's IP_hash mechanism. We use it as a method to solve session problems. It is recommended to pay attention;

⑤ ri, indicates based on the URI of the request;

⑥ rl_param, indicating that 'balance url_param' requires an URL parameter name according to the requested URl parameter;

⑦ hdr(name), indicating that each HTTP request is locked based on the HTTP request header;

⑧ rdp-cookie(name) means locking and hashing each TCP request based on cookie(name).

Summary of the comparison between Nginx and LVS:

Nginx works on layer 7 of the network, so it can implement diversion strategies for the http application itself, such as domain names and directories. Structure, etc. In contrast, LVS does not have such a function, so Nginx can be used in far more situations than LVS based on this alone; but these useful functions of Nginx make it more adjustable than LVS, so it is often You have to touch, touch, touch. If you touch too much, the chances of human problems will increase.

Nginx has less dependence on network stability. In theory, as long as ping is successful and web page access is normal, Nginx can connect. This is a major advantage of Nginx! Nginx can also distinguish between internal and external networks. If it is a node with both internal and external networks, it is equivalent to a single machine having a backup line; LVS is more dependent on the network environment. Currently, the servers are in the same network segment and LVS uses direct mode to offload. The effect is more guaranteed. Also note that LVS needs to apply for at least one more IP from the hosting provider to be used as a Visual IP. It seems that it cannot use its own IP as a VIP. To be a good LVS administrator, you really need to follow up and learn a lot of knowledge about network communication, which is no longer as simple as HTTP.

Nginx is relatively simple to install and configure, and it is also very convenient to test, because it can basically print out errors in the log. The installation, configuration, and testing of LVS take a relatively long time; LVS relies heavily on the network. In many cases, failure to configure successfully is due to network problems rather than configuration problems. If there is a problem, it will be much more troublesome to solve. .

Nginx can also withstand high loads and is stable, but the load and stability are worse than LVS. There are several levels: Nginx handles all traffic, so it is limited by machine IO and configuration; its own bugs are still difficult to solve. Avoided.

Nginx can detect internal server failures, such as status codes, timeouts, etc. returned by the server processing web pages, and will resubmit requests that return errors to another node. Currently, ldirectd in LVS can also support monitoring the internal conditions of the server, but the principle of LVS prevents it from resending requests. For example, if the user is uploading a file, and the node processing the upload fails during the upload process, Nginx will switch the upload to another server for reprocessing, and LVS will be directly disconnected. If a large file is uploaded, Or very important files, users may be annoyed by this.

Nginx’s asynchronous processing of requests can help the node server reduce the load. If apache is used to serve external services directly, then when there are many narrowband links, the apache server will occupy a large amount of memory and cannot be released. Use one more Nginx as apache If you use a proxy, these narrowband links will be blocked by Nginx, and too many requests will not accumulate on Apache, thus reducing a considerable amount of resource usage. Using Squid has the same effect in this regard. Even if Squid itself is configured not to cache, it is still of great help to Apache.

Nginx能支持http、https和email(email的功能比較少用),LVS所支持的應(yīng)用在這點(diǎn)上會(huì)比Nginx更多。在使用上,一般最前端所采取的策略應(yīng)是LVS,也就是DNS的指向應(yīng)為LVS均衡器,LVS的優(yōu)點(diǎn)令它非常適合做這個(gè)任務(wù)。重要的ip地址,最好交由LVS托管,比如數(shù)據(jù)庫的 ip、webservice服務(wù)器的ip等等,這些ip地址隨著時(shí)間推移,使用面會(huì)越來越大,如果更換ip則故障會(huì)接踵而至。所以將這些重要ip交給 LVS托管是最為穩(wěn)妥的,這樣做的唯一缺點(diǎn)是需要的VIP數(shù)量會(huì)比較多。Nginx可作為LVS節(jié)點(diǎn)機(jī)器使用,一是可以利用Nginx的功能,二是可以利用Nginx的性能。當(dāng)然這一層面也可以直接使用squid,squid的功能方面就比Nginx弱不少了,性能上也有所遜色于Nginx。Nginx也可作為中層代理使用,這一層面Nginx基本上無對手,唯一可以撼動(dòng)Nginx的就只有l(wèi)ighttpd了,不過lighttpd目前還沒有能做到 Nginx完全的功能,配置也不那么清晰易讀。另外,中層代理的IP也是重要的,所以中層代理也擁有一個(gè)VIP和LVS是最完美的方案了。具體的應(yīng)用還得具體分析,如果是比較小的網(wǎng)站(日PV小于1000萬),用Nginx就完全可以了,如果機(jī)器也不少,可以用DNS輪詢,LVS所耗費(fèi)的機(jī)器還是比較多的;大型網(wǎng)站或者重要的服務(wù),機(jī)器不發(fā)愁的時(shí)候,要多多考慮利用LVS。

數(shù)據(jù)庫優(yōu)化

44.做秒殺時(shí)鎖表考慮到?jīng)]有?

答:考慮到了,當(dāng)時(shí)我們做秒殺時(shí)考慮了好幾種方案,其中有一種就是使用事務(wù)加上排他鎖來實(shí)現(xiàn)。

45.架構(gòu)類的東西接觸過嗎?

有接觸過,曾經(jīng)自己在自己的服務(wù)器上配置過。我以前做過以下幾個(gè)架構(gòu)方面的配置和測試;

1、數(shù)據(jù)庫的讀寫分離、主從復(fù)制及集群。
2、Nginx負(fù)載均衡
3、redis集群及主從

46.封裝過一個(gè)簡單的框架?

答;封裝過一個(gè)簡單的MVC框架,主要分為3層,控制器層和模型層視圖層,以及路由的分配和入口文件,模板引擎,單例模式、工廠模式,第三方類庫的引入等。

47.談?wù)剬VC的認(rèn)識?

答:核心思想是:視圖和用戶交互通過事件導(dǎo)致控制器改變 控制器改變導(dǎo)致模型改變 或者控制器同時(shí)改變兩者 模型改變 導(dǎo)致視圖改變 或者視圖改變 潛在的從模型里面獲得參數(shù) 來改變自己。他的好處是可以將界面和業(yè)務(wù)邏輯分離。

Model(模型),是程序的主體部分,主要包含業(yè)務(wù)數(shù)據(jù)和業(yè)務(wù)邏輯。在模型層,還會(huì)涉及到用戶發(fā)布的服務(wù),在服務(wù)中會(huì)根據(jù)不同的業(yè)務(wù)需求,更新業(yè)務(wù)模型中的數(shù)據(jù)。
View(視圖),是程序呈現(xiàn)給用戶的部分,是用戶和程序交互的接口,用戶會(huì)根據(jù)具體的業(yè)務(wù)需求,在View視圖層輸入自己特定的業(yè)務(wù)數(shù)據(jù),并通過界面的事件交互,將對應(yīng)的輸入?yún)?shù)提交給后臺控制器進(jìn)行處理。
Contorller(控制器),Contorller是用來處理用戶 輸入數(shù)據(jù),已經(jīng)更新業(yè)務(wù)模型的部分??刂破髦薪邮樟擞脩襞c界面交互時(shí)傳遞過來的數(shù)據(jù),并根據(jù)數(shù)據(jù)業(yè)務(wù)邏輯來執(zhí)行服務(wù)的調(diào)用和更新業(yè)務(wù)模型的數(shù)據(jù)和狀態(tài)。

48.session與cookie的區(qū)別?

1、cookie數(shù)據(jù)存放在第三方應(yīng)用的瀏覽器上,session數(shù)據(jù)放在服務(wù)器上。

2、cookie不是很安全,別人可以分析存放在本地的COOKIE,進(jìn)行COOKIE欺騙,考慮到安全應(yīng)當(dāng)使用session。

3、session會(huì)在一定時(shí)間內(nèi)保存在服務(wù)器上。當(dāng)訪問增多,會(huì)比較占用你服務(wù)器的性能,考慮到減輕服務(wù)器性能方面,應(yīng)當(dāng)使用COOKIE。

4、單個(gè)cookie保存的數(shù)據(jù)不能超過4K,很多瀏覽器都限制一個(gè)站點(diǎn)最多保存20個(gè)cookie。

5、所以個(gè)人建議:
    將登陸信息等重要信息存放為SESSION
    其他信息如果需要保留,可以放在COOKIE

49.echo(),print(),print_r()的區(qū)別?

echo可以一次輸出多個(gè)值,多個(gè)值之間用逗號分隔。echo是語言結(jié)構(gòu)(language construct),而并不是真正的函數(shù),因此不能作為表達(dá)式的一部分使用。echo是php的內(nèi)部指令,不是函數(shù),無返回值。

print():函數(shù)print()打印一個(gè)值(它的參數(shù)),如果字符串成功顯示則返回true,否則返回false。只能打印出簡單類型變量的值(如int,string),有返回值

printf():源于C語言中的printf()。該函數(shù)輸出格式化的字符串。

print_r()和var_dump()
print_r()可以把字符串和數(shù)字簡單地打印出來,而數(shù)組則以括起來的鍵和值得列表形式顯示,并以Array開頭。但print_r()輸出布爾值和NULL的結(jié)果沒有意義,因?yàn)槎际谴蛴?quot;\n"。因此用var_dump()函數(shù)更適合調(diào)試。print_r是函數(shù),可以打印出比較復(fù)雜的變量(如數(shù)組,對象),有返回值
var_dump()判斷一個(gè)變量的類型與長度,并輸出變量的數(shù)值,如果變量有值輸?shù)氖亲兞康闹挡⒒胤禂?shù)據(jù)類型。此函數(shù)顯示關(guān)于一個(gè)或多個(gè)表達(dá)式的結(jié)構(gòu)信息,包括表達(dá)式的類型與值。數(shù)組將遞歸展開值,通過縮進(jìn)顯示其結(jié)構(gòu)。

50.說一下單引號雙引號?

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

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

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

51.索引的優(yōu)缺點(diǎn)?

1、優(yōu)點(diǎn):

a)可以保證數(shù)據(jù)庫表中每一行的數(shù)據(jù)的唯一性
b)可以大大加快數(shù)據(jù)的索引速度
c)加速表與表之間的連接,物別是在實(shí)現(xiàn)數(shù)據(jù)的參考完事性方面特別有意義
d)在使用分組和排序子句進(jìn)行數(shù)據(jù)檢索時(shí),同樣可以顯著減少查詢中分組和排序的時(shí)間
f)通過使用索引,可以在時(shí)間查詢的過程中,使用優(yōu)化隱藏器,提高系統(tǒng)的性能

2、 缺點(diǎn):

a)  創(chuàng)建索引和維護(hù)索引要耗費(fèi)時(shí)間,這種時(shí)間隨著數(shù)據(jù)量的增加而增加
b)  索引需要占物理空間,除了數(shù)據(jù)表占用數(shù)據(jù)空間之外,每一個(gè)索引還要占用一定的物理空間,如果需要建立聚簇索引,那么需要占用的空間會(huì)更大
c)  以表中的數(shù)據(jù)進(jìn)行增、刪、改的時(shí)候,索引也要?jiǎng)討B(tài)的維護(hù),這就降低了整數(shù)的維護(hù)速度
d)  建立索引的原則
e)  在經(jīng)常需要搜索的列上,可以加快搜索的速度
f)  在作為主鍵的列上,強(qiáng)制該列的唯一性和組織表中數(shù)據(jù)的排列結(jié)構(gòu)
g)  在經(jīng)常用在連接的列上,這些列主要是一外鍵,可以加快連接的速度
h)  在經(jīng)經(jīng)常需要根據(jù)范圍進(jìn)行搜索的列上創(chuàng)建索引,國為索引已經(jīng)排序,其指定的范圍是連續(xù)的
i)  在經(jīng)常需要排序的列上,國為索引已經(jīng)排序,這樣井底可以利用索引的排序,加快排序井底時(shí)間
j)  在經(jīng)常使用在where子句中的列上,加快條件的判斷速度

52.get和post的區(qū)別?

1. get是從服務(wù)器上獲取數(shù)據(jù),post是向服務(wù)器傳送數(shù)據(jù)。
2. get是把參數(shù)數(shù)據(jù)隊(duì)列加到提交表單的ACTION屬性所指的URL中,值和表單內(nèi)各個(gè)字段一一對應(yīng),在URL中可以看到。post是通過HTTP post機(jī)制,將表單內(nèi)各個(gè)字段與其內(nèi)容放置在HTML HEADER內(nèi)一起傳送到ACTION屬性所指的URL地址。用戶看不到這個(gè)過程。
3. get傳送的數(shù)據(jù)量較小,不能大于2KB。post傳送的數(shù)據(jù)量較大,一般被默認(rèn)為不受限制。
4. get安全性非常低,post安全性較高。但是執(zhí)行效率卻比Post方法好。

53.如何修改會(huì)話的生存時(shí)間?

一:在php.ini中設(shè)置session.gc_maxlifetime = 1440 //默認(rèn)時(shí)間
二:代碼實(shí)現(xiàn)      $ lifeTime = 24 * 3600; //保存一天
    session_set_cookie_params($ lifeTime); 
    在session_start();

54.Linux基本命令,目錄結(jié)構(gòu)?

arch顯示機(jī)器的處理器架構(gòu)
(1) uname -m顯示機(jī)器的處理器架構(gòu)
(2) uname -r顯示正在使用的內(nèi)核版本 
dmidecode -q顯示硬件系統(tǒng)部件 - (SMBIOS / DMI)   
hdparm -i / dev / hda羅列一個(gè)磁盤的架構(gòu)特性    
hdparm -tT / dev / sda在磁盤上執(zhí)行測試性讀取操作 
cat / porc / cpuinfo顯示CPU信息 
cat / porc / interrupts顯示中斷
cat / porc / meminfo校驗(yàn)內(nèi)存使用  
cat / porc / swaps顯示哪些交換被使用 
cat / porc / verion顯示內(nèi)核的版本
cat /porc/net/dev 顯示網(wǎng)絡(luò)適配器及統(tǒng)計(jì) 
cat /porc/mounts 顯示已加載的文件系統(tǒng) 

date 顯示系統(tǒng)日期 
cal 2007 顯示2007年的日歷表 
date 041217002007.00 設(shè)置日期和時(shí)間 -月日時(shí)分年.秒 
clock -w 將時(shí)間修改保存到 BIOS 

文件搜索 
find / -name file1 從 '/'開始進(jìn)入根文件系統(tǒng)搜索文件和目錄 

locate \*.ps 尋找以 '.ps'結(jié)尾的文件 -先運(yùn)行'updatedb'命令 
whereis halt 顯示一個(gè)二進(jìn)制文件、源碼或man的位置 
which halt 顯示一個(gè)二進(jìn)制文件或可執(zhí)行文件的完整路徑 

掛載一個(gè)文件系統(tǒng) 
mount /dev/hda2 /mnt/hda2 掛載一個(gè)叫做hda2的盤- 確定目錄'/ mnt/hda2' 已經(jīng)存在 
umount /dev/hda2 卸載一個(gè)叫做hda2的盤- 先從掛載點(diǎn)'/ mnt/hda2' 退出 

追加命令

1,linux里把文件/etc/aaa中的內(nèi)容追加到/usr/bbb中的內(nèi)容的后面
  sudo cat /etc/aaa >>/usr/bbb
2,更改/etc/index.html的文件所有者為apache,文件群組為apache
  sudo chmod apache:apache  /etc/index.html
3,更改/etc/index.html的所有者權(quán)限為讀取、寫入、執(zhí)行。群組權(quán)限為讀取。其他權(quán)限為讀取
  sudo chmod 744 /etc/index.html
4,刪除/etc下名為hello的文件
  sudo rm /etc/index.html

當(dāng)然,如果你是以orot用戶執(zhí)行以上操作,可以去掉前邊的sudo!

df -hl 查看磁盤剩余空間

df -h 查看每個(gè)根路徑的分區(qū)大小

du -sh [目錄名] 返回該目錄的大小

du -sm [文件夾] 返回該文件夾總M數(shù)

關(guān)機(jī) (系統(tǒng)的關(guān)機(jī)、重啟以及登出) 
shutdown -h now 關(guān)閉系統(tǒng)(1) 
init 0 關(guān)閉系統(tǒng)(2) 
telinit 0 關(guān)閉系統(tǒng)(3) 
shutdown -h hour:minutes & 按預(yù)定時(shí)間關(guān)閉系統(tǒng) 
shutdown -c 取消按預(yù)定時(shí)間關(guān)閉系統(tǒng) 
shutdown -r now 重啟(1) 
reboot 重啟(2) 
logout 注銷

文件和目錄 
pwd 顯示工作路徑 
ls 查看目錄中的文件 
ls -F 查看目錄中的文件 
ls -l 顯示文件和目錄的詳細(xì)資料 
ls -a 顯示隱藏文件 
ls *[0-9]* 顯示包含數(shù)字的文件名和目錄名 
tree 顯示文件和目錄由根目錄開始的樹形結(jié)構(gòu)(1) 
lstree 顯示文件和目錄由根目錄開始的樹形結(jié)構(gòu)(2) 
mkdir dir1 創(chuàng)建一個(gè)叫做 'dir1'的目錄' 

磁盤空間 
df -h 顯示已經(jīng)掛載的分區(qū)列表 
ls -lSr |more 以尺寸大小排列文件和目錄 
du -sh dir1 估算目錄 'dir1'已經(jīng)使用的磁盤空間' 

下載、解壓

1)對于.tar結(jié)尾的文件 
  tar -xf all.tar 

2)對于.gz結(jié)尾的文件 
  gzip -d all.gz 
  gunzip all.gz 

# zip all.zip *.jpg 
  這條命令是將所有.jpg的文件壓縮成一個(gè)zip包 
# unzip all.zip 
  這條命令是將all.zip中的所有文件解壓出來

下載命令

wget + 空格 +要下載文件的url路徑

=====================================

Shell 腳本:

必須以  #!/bin/sh  開頭

簡單例子:判斷這個(gè)目錄下有沒有文件(File)

#!/bin/bash
Num=`ls -al /opt |grep "^-"|wc -l `
if [ $Num != 0 ]
 then echo "/opt has $Num files"
else
 echo "/opt has none file"
fi

ls -al /opt |grep "^-"|wc -l  這個(gè)命令能夠統(tǒng)計(jì)文件個(gè)數(shù) 為0就是沒有文件 非零就是有文件

55..memcache緩存什么數(shù)據(jù)?

一、經(jīng)常被讀取并且實(shí)時(shí)性要求不強(qiáng)可以等到自動(dòng)過期的數(shù)據(jù)。例如網(wǎng)站首頁最新文章列表、某某排行等數(shù)據(jù)。
二、經(jīng)常被讀取并且實(shí)時(shí)性要求強(qiáng)的數(shù)據(jù)。比如用戶的好友列表,用戶文章列表,用戶閱讀記錄等。
三、統(tǒng)計(jì)類緩存,比如文章瀏覽數(shù)、網(wǎng)站PV等。
四、活躍用戶的基本信息或者某篇熱門文章。
五、session數(shù)據(jù)

56.魔術(shù)方法、魔術(shù)常量?

1。__construct()
實(shí)例化對象時(shí)被調(diào)用,當(dāng)__construct和以類名為函數(shù)名的函數(shù)同時(shí)存在時(shí),__construct將被調(diào)用,另一個(gè)不被調(diào)用。
2。__destruct()
當(dāng)刪除一個(gè)對象或?qū)ο蟛僮鹘K止時(shí)被調(diào)用。
3。__call()
對象調(diào)用某個(gè)方法,若方法存在,則直接調(diào)用;若不存在,則會(huì)去調(diào)用__call函數(shù)。
4。__get()
讀取一個(gè)對象的屬性時(shí),若屬性存在,則直接返回屬性值;若不存在,則會(huì)調(diào)用__get函數(shù)。
5。__set()
設(shè)置一個(gè)對象的屬性時(shí),若屬性存在,則直接賦值;若不存在,則會(huì)調(diào)用__set函數(shù)。
6。__toString()
打印一個(gè)對象的時(shí)被調(diào)用。如echo $obj;或print $obj;
7。__clone()
克隆對象時(shí)被調(diào)用。如:$t=new Test();$t1=clone $t;
8。__sleep()
serialize之前被調(diào)用。若對象比較大,想刪減一點(diǎn)東東再序列化,可考慮一下此函數(shù)。
9。__wakeup()
unserialize時(shí)被調(diào)用,做些對象的初始化工作。
10。__isset()
檢測一個(gè)對象的屬性是否存在時(shí)被調(diào)用。如:isset($c->name)。
11。__unset()
unset一個(gè)對象的屬性時(shí)被調(diào)用。如:unset($c->name)。
12。__set_state()
調(diào)用var_export時(shí),被調(diào)用。用__set_state的返回值做為var_export的返回值。
13。__autoload()
實(shí)例化一個(gè)對象時(shí),如果對應(yīng)的類不存在,則該方法被調(diào)用。

魔術(shù)常量:

__LINE__
返回文件中的當(dāng)前行號。

__FILE__
返回文件的完整路徑和文件名。如果用在包含文件中,則返回包含文件名。自 PHP 4.0.2 起,__FILE__ 總是包含一個(gè)絕對路徑,而在此之前的版本有時(shí)會(huì)包含一個(gè)相對路徑。

__FUNCTION__
返回函數(shù)名稱(PHP 4.3.0 新加)。自 PHP 5 起本常量返回該函數(shù)被定義時(shí)的名字(區(qū)分大小寫)。在PHP 4 中該值總是小寫字母的。

__CLasS__
返回類的名稱(PHP 4.3.0 新加)。自 PHP 5 起本常量返回該類被定義時(shí)的名字(區(qū)分大小寫)。在PHP 4 中該值總是小寫字母的。

__METHOD__
返回類的方法名(PHP 5.0.0 新加)。返回該方法被定義時(shí)的名字(區(qū)分大小寫)。

__set()當(dāng)程序試圖寫入一個(gè)不存在或者不可見的成員變量時(shí),__set()方法包含兩個(gè)參數(shù),分別表示變量名稱和變量值,兩個(gè)參數(shù)都不可省略

__get()當(dāng)程序試圖調(diào)用一個(gè)未定義或不可見的成員變量時(shí),__get()方法有一個(gè)參數(shù),表示要調(diào)用的變量名

__sleep() 常用于提交未提交的數(shù)據(jù),或類似的清理操作如果有一些很大的對象,但不需要全部保存,這個(gè)功能就很好用。

__construct()  在類實(shí)例化對象的同時(shí)執(zhí)行該函數(shù)

__distruct() 在類實(shí)例化的對象銷毀時(shí)執(zhí)行

__call()對象調(diào)用某個(gè)方法,若方法存在,則直接調(diào)用;若不存在,則會(huì)去調(diào)用__call函數(shù)。

__clone()克隆對象時(shí)被調(diào)用。如:$t=new Test();$t1=clone $t;

__toString()打印一個(gè)對象的時(shí)被調(diào)用。如echo $obj;或print $obj;

__isset()檢測一個(gè)對象的屬性是否存在時(shí)被調(diào)用。如:isset($c->name)。

__unset()unset一個(gè)對象的屬性時(shí)被調(diào)用。如:unset($c->name)。

__autoload()實(shí)例化一個(gè)對象時(shí),如果對應(yīng)的類不存在,則該方法被調(diào)用。

57.接口和抽象類的區(qū)別是什么?

答:抽象類是一種不能被實(shí)例化的類,只能作為其他類的父類來使用。抽象類是通過關(guān)鍵字abstract來聲明的。?

抽象類與普通類相似,都包含成員變量和成員方法,兩者的區(qū)別在于,抽象類中至少要包含一個(gè)抽象方法,抽象方法沒有方法體,該方法天生就是要被子類重寫的。?

抽象方法的格式為:abstract function abstractMethod();

接口是通過 interface 關(guān)鍵字來聲明的,接口中的成員常量和方法都是 public 的,方法可以不寫關(guān)鍵字public,接口中的方法也是沒有方法體。接口中的方法也天生就是要被子類實(shí)現(xiàn)的。?

抽象類和接口實(shí)現(xiàn)的功能十分相似,最大的不同是接口能實(shí)現(xiàn)多繼承。在應(yīng)用中選擇抽象類還是接口要看具體實(shí)現(xiàn)。?

子類繼承抽象類使用 extends,子類實(shí)現(xiàn)接口使用implements。

58.什么是隊(duì)列?排它鎖,Myisam死鎖如何解決?

答:在默認(rèn)情況下MYisam是表級鎖,所以同時(shí)操作單張表的多個(gè)動(dòng)作只能以隊(duì)列的方式進(jìn)行;

排它鎖又名寫鎖,在SQL執(zhí)行過程中為排除其它請求而寫鎖,在執(zhí)行完畢后會(huì)自動(dòng)釋放;

死鎖解決:先找到死鎖的線程號,然后殺掉線程ID

59.bootstrap框架有哪些優(yōu)點(diǎn)?

答:bootstrap是一款web開發(fā)框架,它由CSS,JavaScript,Html,三部分構(gòu)成,它簡潔靈活,使得web開發(fā)更加的快捷

優(yōu)點(diǎn):?

① Save time: Using the bootstrap framework can greatly save project development time. It contains a lot of ready-made code. If you need to use it, you only need to find the appropriate code and insert it into the appropriate position. In addition, CSS is used Written in LESS, many styles and designs have been designed

② Customization: bootstrap can keep the parts of the framework that you need according to your own project

③ Reasonable design:

Grid system: bootstrap defines a 12-grid system. When the page is completed, you can change the number of rows and layout size according to your own needs according to the appropriate grid. The style has been developed, and you only need to put the code Just enter the appropriate HTML code position

LESS: LESS is a high-level language based on CSS. Its purpose is to make CSS development more flexible and powerful

JavaScript: bootstrap provides a JavaScript library. This library goes beyond the basic architecture and styles. Developers can easily operate window warning boxes, tool tip boxes, etc., which can avoid us having to spend time and effort writing scripts

4. Consistency: bootstrap can ensure that the interface is consistent The unity of different platforms, whether it is IE, Chrome, etc.

5. Continuous updates: bootstrap is constantly improving, making it more regular and sustainable

6. Responsiveness: whether it is Both the PC and mobile terminals can maintain the consistency of the interface

7. Lots of documentation: There are a lot of bootstraps

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)