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

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

藏色散人
Release: 2022-12-19 16:36:17
forward
106155 people have browsed it

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具有三大特点
Copy after login

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设定了缓存参数以后,第一次运行时候会把模板打开,在php替换里面值的时候把读取的html和php部分重新生成一个临时的php文件,这样就省去了每次打开都重新读取html了。如果修改了模板,只要重新刷下就行了。

10.TP框架有哪些优点?

答:TP框架是我们中国人自己开发的框架,各种资料比较齐全,国内用的比较多,比较简单和方便,而且是免费开源的

11.TP的特性有哪些?

1.多表查询非常方便,在model中几句代码就可以完成对多表的关联操作
2.融合了smarty模板,使前后台分离
3.支持多种缓存技术,尤其对memcache技术支持非常好
4.命名规范,模型,视图,控制器严格遵循命名规则,通过命名一一对应
5.支持多种url模式
6.内置ajax返回方法,包括xml,json,html等
7.支持应用扩展,类库扩展,驱动扩展等
Copy after login

12.TP框架中的大字母函数?

U:对url的组装
A:内部实例化控制器
S:缓存处理
R:调用某个控制器的操作方法
D:实例化自定义模型类
M:实例化基础模型类
I:获取参数
L:设置或者获取当前语言
C:设置或获取,保存配置
Copy after login

13.请介绍一下laravel框架?

答: laravel框架的设计思想比较先进,非常适合应用各种开发模式,作为一个框架,它为你准备好了一切,composer是php的未来,没有composer,php肯定要走向没落

laravel框架最大的特点和优秀之处就是集合了php比较新的特点,以及各种各样的设计模式,Ioc模式,依赖注入等

14.laravel有那些特点?

回答一:

1.强大的rest router:用简单的回调函数就可以调用,快速绑定controller和router
2.artisan:命令行工具,很多手动的工作都自动化
3.可继承的模板,简化view的开发和管理
4.blade模板:渲染速度更快
5.ORM操作数据库
6.migration:管理数据库和版本控制
7.测试功能也很强大
8.composer也是亮点
Copy after login

回答二: laravel框架引入了门面,依赖注入,Ioc模式,以及各种各样的设计模式等

15.请简述一下数据库的优化?

答:数据库的优化可以从四个方面来优化:

1.从结构层: web服务器采用负载均衡服务器,mysql服务器采用主从复制,读写分离
2.从储存层: 采用合适的存储引擎,采用三范式
3.从设计层: 采用分区分表,索引,表的字段采用合适的字段属性,适当的采用逆范式,开启mysql缓存
4.sql语句层:结果一样的情况下,采用效率高,速度快节省资源的sql语句执行
Copy after login

16.如何解决异常处理?

答: 抛出异常:使用try…catch,异常的代码放在try代码块内,如果没有触发异常,则代码继续执行,如果异常被触发,就会 抛出一个异常。Catch代码块捕获异常,并创建一个包含异常信息的对象。$e->getMessage(),输出异常的错误信息。

解决异常:使用set_error_handler函数获取异常(也可以使用try()和catch()函数),然后使用set_exception_handler()函数设置默认的异常处理程序,register_shutdown_function()函数来执行,执行机制是,php要把调入的函数调入到内存,当页面所有的php语句都执行完成时,再调用此函数

17.前端?

答:我在工作中处理前端的功能,一般就是用ajax向后台请求数据,然后返回数据在前台页面中显示出来。我从来没有独立的完整的将html和css样式都一个人完成,如果公司实在有这样的需求的话,我可能会找一些前台的模板或者说是前端的框架,比如说h—ui等等

18.权限管理(RBAC)的实现?

1.首先创建一张用户表:id name auto(保存格式为:控制器-方法)

2.然后在后台中创建一个基类控制器,控制器里封装一个构造方法,当用户登陆成功后,使用TP框架中封装好的session函数获取保存在服务器中的session id,然后实例化模型,通过用户id获取保存在数据表中的auth数据,使用explode函数分割获取到的数据,并使用一个数组保存起来,然后使用TP框架中封装好的常量获取当前控制器和方法,然后把他们组装成字符串,使用in_array函数进行判断该数组中是否含有当前获取到的控制器和方法,如果没有,就提示该用户没有权限,如果有就进行下一步操作

19.支付功能的实现?

答:

20.怎么保证促销商品不会超卖?

答:这个问题是我们当时开发时遇到的一个难点,超卖的原因主要是下的订单的数目和我们要促销的商品的数目不一致导致的,每次总是订单的数比我们的促销商品的数目要多,当时我们的小组讨论了好久,给出了好几个方案来实现:

第一种方案:在每次下订单前我们判断促销商品的数量够不够,不够不允许下订单,更改库存量时加上一个条件,只更改商品库存大于0的商品的库存,当时我们使用ab进行压力测试,当并发超过500,访问量超过2000时,还是会出现超卖现象。所以被我们否定了。

第二种方案:使用mysql的事务加排他锁来解决,首先我们选择数据库的存储引擎为innoDB,使用的是排他锁实现的,刚开始的时候我们测试了下共享锁,发现还是会出现超卖的现象。有个问题是,当我们进行高并发测试时,对数据库的性能影响很大,导致数据库的压力很大,最终也被我们否定了。

第三种方案:使用文件锁实现。当用户抢到一件促销商品后先触发文件锁,防止其他用户进入,该用户抢到促销品后再解开文件锁,放其他用户进行操作。这样可以解决超卖的问题,但是会导致文件得I/O开销很大。

最后我们使用了redis的队列来实现。将要促销的商品数量以队列的方式存入redis中,每当用户抢到一件促销商品则从队列中删除一个数据,确保商品不会超卖。这个操作起来很方便,而且效率极高,最终我们采取这种方式来实现

21.商城秒杀的实现?

答:抢购、秒杀是如今很常见的一个应用场景,主要需要解决的问题有两个:

1 高并发对数据库产生的压力
2 竞争状态下如何解决库存的正确减少("超卖"问题)
Copy after login

对于第一个问题,已经很容易想到用缓存来处理抢购,避免直接操作数据库,例如使用Redis。第二个问题,我们可以使用redis队列来完成,把要秒杀的商品放入到队列中,因为pop操作是原子的,即使有很多用户同时到达,也是依次执行,文件锁和事务在高并发下性能下降很快,当然还要考虑其他方面的东西,比如抢购页面做成静态的,通过ajax调用接口,其中也可能会出现一个用户抢多次的情况,这时候需要再加上一个排队队列和抢购结果队列及库存队列。高并发情况下,将用户进入排队队列,用一个线程循环处理从排队队列取出一个用户,判断用户是否已在抢购结果队列,如果在,则已抢购,否则未抢购,库存减1,写数据库,将用户入结果队列。

22.购物车的原理?

答:购物车相当于现实中超市的购物车,不同的是一个是实体车,一个是虚拟车而已。用户可以在购物网站的不同页面之间跳转,以选购自己喜爱的商品,点击购买时,该商品就自动保存到你的购物车中,重复选购后,最后将选中的所有商品放在购物车中统一到付款台结账,这也是尽量让客户体验到现实生活中购物的感觉。服务器通过追踪每个用户的行动,以保证在结账时每件商品都物有其主。

主要涉及以下几点:

    1、把商品添加到购物车,即订购
    2、删除购物车中已定购的商品
    3、修改购物车中某一本图书的订购数量
    4、清空购物车
    5、显示购物车中商品清单及数量、价格
Copy after login

实现购物车的关键在于服务器识别每一个用户并维持与他们的联系。但是HTTP协议是一种“无状态(Stateless)”的协议,因而服务器不能记住是谁在购买商品,当把商品加入购物车时,服务器也不知道购物车里原先有些什么,使得用户在不同页面间跳转时购物车无法“随身携带”,这都给购物车的实现造成了一定的困难。

目前购物车的实现主要是通过cookie、session或结合数据库的方式。下面分析一下它们的机制及作用。

cookie

cookie是由服务器产生,存储在客户端的一段信息。它定义了一种Web服务器在客户端存储和返回信息的机制,cookie文件它包含域、路径、生存期、和由服务器设置的变量值等内容。当用户以后访问同一个Web服务器时,浏览器会把cookie原样发送给服务器。通过让服务器读取原先保存到客户端的信息,网站能够为浏览者提供一系列的方便,例如在线交易过程中标识用户身份、安全要求不高的场合避免用户重复输入名字和密码、门户网站的主页定制、有针对性地投放广告等等。利用cookie的特性,大大扩展了WEB应用程序的功能,不仅可以建立服务器与客户机的联系,因为cookie可以由服务器定制,因此还可以将购物信息生成cookie值存放在客户端,从而实现购物车的功能。用基于cookie的方式实现服务器与浏览器之间的会话或购物车,有以下特点:

1、cookie存储在客户端,且占用很少的资源,浏览器允许存放300个cookie,每个cookie的大小为4KB,足以满足购物车的要求,同时也减轻了服务器的负荷;
2、cookie为浏览器所内置,使用方便。即使用户不小心关闭了浏览器窗口,只要在cookie定义的有效期内,购物车中的信息也不会丢失;
3、cookie不是可执行文件,所以不会以任何方式执行,因此也不会带来病毒或攻击用户的系统;
4、基于cookie的购物车要求用户浏览器必须支持并设置为启用cookie,否则购物车则失效;
5、存在着关于cookie侵犯访问者隐私权的争论,因此有些用户会禁止本机的cookie功能。
Copy after login

session

session是实现购物车的另一种方法。session提供了可以保存和跟踪用户的状态信息的功能,使当前用户在session中定义的变量和对象能在页面之间共享,但是不能为应用中其他用户所访问,它与cookie最重大的区别是,session将用户在会话期间的私有信息存储在服务器端,提高了安全性。在服务器生成session后,客户端会生成一个sessionid识别号保存在客户端,以保持和服务器的同步。这个sessionid是只读的,如果客户端禁止cookie功能,session会通过在URL中附加参数,或隐含在表单中提交等其他方式在页面间传送。因此利用session实施对用户的管理则更为安全、有效。

同样,利用session也能实现购物车,这种方式的特点是:

1、session用新的机制保持与客户端的同步,不依赖于客户端设置;
2、与cookie相比,session是存储在服务器端的信息,因此显得更为安全,因此可将身份标示,购物等信息存储在session中;
3、session会占用服务器资源,加大服务器端的负载,尤其当并发用户很多时,会生成大量的session,影响服务器的性能;
4、因为session存储的信息更敏感,而且是以文件形式保存在服务器中,因此仍然存在着安全隐患。
Copy after login

结合数据库的方式

这也是目前较普遍的模式,在这种方式中,数据库承担着存储购物信息的作用,session或cookie则用来跟踪用户。这种方式具有以下特点:

1、数据库与cookie分别负责记录数据和维持会话,能发挥各自的优势,使安全性和服务器性能都得到了提高;
2、每一个购物的行为,都要直接建立与数据库的连接,直至对表的操作完成后,连接才释放。当并发用户很多时,会影响数据库的性能,因此,这对数据库的性能提出了更高的要求;
3、使cookie维持会话有赖客户端的支持。
Copy after login

各种方式的选择:

虽然cookie可用来实现购物车,但必须获得浏览器的支持,再加上它是存储在客户端的信息,极易被获取,所以这也限制了它存储更多,更重要的信息。所以一般cookie只用来维持与服务器的会话,例如国内最大的当当网络书店就是用cookie保持与客户的联系,但是这种方式最大的缺点是如果客户端不支持cookie就会使购物车失效。

Session能很好地与交易双方保持会话,可以忽视客户端的设置。在购物车技术中得到了广泛的应用。但session的文件属性使其仍然留有安全隐患。

结合数据库的方式虽然在一定程度上解决了上述的问题,但从上面的例子可以看出:在这种购物流程中涉及到对数据库表的频繁操作,尤其是用户每选购一次商品,都要与数据库进行连接,当用户很多的时候就加大了服务器与数据库的负荷。

23.redis消息队列先进先出需要注意什么?

答:通常使用一个list来实现队列操作,这样有一个小限制,所以的任务统一都是先进先出,如果想优先处理某个任务就不太好处理了,这就需要让队列有优先级的概念,我们就可以优先处理高级别的任务,实现方式有以下几种方式:

1)单一列表实现:队列正常的操作是 左进右出(lpush,rpop)为了先处理高优先级任务,在遇到高级别任务时,可以直接插队,直接放入队列头部(rpush),这样,从队列头部(右侧)获取任务时,取到的就是高优先级的任务(rpop)

2)使用两个队列,一个普通队列,一个高级队列,针对任务的级别放入不同的队列,获取任务时也很简单,redis的BRPOP命令可以按顺序从多个队列中取值,BRPOP会按照给出的 key 顺序查看,并在找到的第一个非空 list 的尾部弹出一个元素,redis> BRPOP list1 list2 0

list1 做为高优先级任务队列
list2 做为普通任务队列

这样就实现了先处理高优先级任务,当没有高优先级任务时,就去获取普通任务

方式1最简单,但实际应用比较局限,方式3可以实现复杂优先级,但实现比较复杂,不利于维护

方式2是推荐用法,实际应用最为合适
Copy after login

24.你负责的模块有哪些难题?

答:在我负责的B2B电商项目中,当时我负责的是订单模块,由于客户一次选择了多家商户的商品,最终生成了一个订单,这样我们平台在给商户结算时出现了不知道这比费用应该给哪个商户,这时候我们小组经过讨论,需要涉及到订单拆分,也就是说用户点击支付后,如果有多件商品,并且不是同一家店铺那么 就要用到订单的拆分,比如如果有两件商品,并且不是同一店铺 就在原来的订单号下 在生成两个子订单号 并修改订单表中两件商品的订单号。最终实现了商品的分配管理,解决了我们的难题。

我觉得在开发过程中,遇到的难题无非是两个,一个是技术层次的,我认为,只要你有恒心,有热心,没有觉得不了的难题。另一个就是沟通问题,在任何地方任何时候沟通都是最重要的,尤其是我们做开发的,不沟通好,会影响整个项目的进度,我本人是个非常还沟通的人,所以这点上也没多大问题。

25.用户下单是怎么处理的?

答:判断用户有没有登录,在没有登录的情况下,不允许下单。登陆后,可进行下单,并生成唯一的订单号,此时订单的状态为未支付。

26.电商的登录是怎么实现的?

答:分为普通登录和第三方登录 这边主要说一下第三方登录吧,第三方登陆主要使用的是author协议,我就以QQ的第三方登陆为例来进行说明:当用户在我们的站点请求QQ的第三方登陆时,我们站点会引导用户跳转到QQ的登陆授权界面, 当用户输入QQ和密码成功登录以后会自动跳回到我们站点设置好的回调页面,并附带一个code参数,接着你使用code再次去请求QQ的授权页面,就可以从中获取到一个access token(访问令牌),通过这个access_token,我们可以调用QQ提供给我们的接口,比如获取open_id,可以获取用户的基本信息。获取到之后,我们需要拿用户的授权信息和open_id和我们平台的普通用户进行绑定。这样不管是普通用户登陆还是第三方登陆用户,都可以实现登陆。

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

答:我们当时是这么做的,使用HTTP的POST方式,对固定参数+附加参数进行数字签名,使用的是md5加密,比如:我想通过标题获取一个信息,在客户端使用 信息标题+日期+双方约定好的一个key通过md5加密生成一个签名(sign),然后作为参数传递到服务器端,服务器端使用同样的方法进行校验,如何接受过来的sign和我们通过算法算的值相同,证明是一个正常的接口请求,我们才会返回相应的接口数据。

28.用的什么技术实现短信发送,在哪调用?

答:我主要用的第三方短信接口,在申请接口时进行相应信息的配置,然后在我们站点需要用到短信验证的地方进行调用,我们通常在用户注册时使用到。

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

答:总体来说:在工作我主要遇到这几个问题比较难处理:

① 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模式奉行的是“线上支付+实体店消费”的消费模式,即消费者在网上下单完成支付后,凭消费凭证到实体店消费。 O2O模式是把商家信息和支付程序放在线上进行,而把商品和服务兑现放在线下,也就是说O2O模式适用于快递无法送达的有形产品。数据一致性的问题是O2O行业中最常见的问题,我们可以类似于数据库的主从复制的思路来解决这个问题.O2O有个供应商系统,类似于主服务器,在ç端(从服务器)下单时,数据同步更新到供应商系统端,b,a实时从供应商系统中拉取数据进行同步,比如利用定时任务,定时拉取数据进行同步。

36.Redis如何防止高并发?

答:其实redis是不会存在并发问题的,因为他是单进程的,再多的命令都是一个接一个地执行的。我们使用的时候,可能会出现并发问题,比如获得和设定这一对。Redis的为什么 有高并发问题?Redis的的出身决定

Redis是一种单线程机制的nosql数据库,基于key-value,数据可持久化落盘。由于单线程所以redis本身并没有锁的概念,多个客户端连接并不存在竞争关系,但是利用jedis等客户端对redis进行并发访问时会出现问题。发生连接超时、数据转换错误、阻塞、客户端关闭连接等问题,这些问题均是由于客户端连接混乱造成。

同时,单线程的天性决定,高并发对同一个键的操作会排队处理,如果并发量很大,可能造成后来的请求超时。

在远程访问redis的时候,因为网络等原因造成高并发访问延迟返回的问题。

解决办法

在客户端将连接进行池化,同时对客户端读写Redis操作采用内部锁synchronized。

服务器角度,利用setnx变向实现锁机制。

37.秒杀当中的细节你是怎么得出来的?

答:通过性能测试及模拟秒杀场景。每个问题都经过反复测试,不断的发现问题,不断的解决。

38.做秒杀用什么数据库,怎么实现的?

答:因为秒杀的一瞬间,并发非常大,如果同时请求数据库,会导致数据库的压力非常大,导致数据库的性能急剧下降,更严重的可能会导致数据库服务器宕机。这时候一般采用内存高速缓存数据库redis来实现的,redis是非关系型数据库,redis是单线程的,通过redis的队列可以完成秒杀过程。

39.支付宝流程怎么实现的?

答:首先要有一个支付宝账号,接下来向支付宝申请在线支付业务,签署协议。协议生效后有支付宝一方会给网站方一个合作伙伴ID,和安全校验码,有了这两样东西就可以按照支付宝接口文档开发支付宝接口了,中间主要涉及到一个安全问题。整个流程是这样的:我们的网站通过post传递相应的参数(如订单总金额,订单号)到支付页面,支付页面把一系列的参数经过处理,以post的方式提交给支付宝服务器,支付宝服务器进行验证,并对接收的数据进行处理,把处理后的结果返回给我们网站设置的异步和同步回调地址,通过相应的返回参数,来处理相应的业务逻辑,比如返回的参数代表支付成功,更改订单状态。

40.什么是单点登录?

答:单点登录SSO(Single Sign On)说得简单点就是在一个多系统共存的环境下,用户在一处登录后,就不用在其他系统中登录,也就是用户的一次登录能得到其他所有系统的信任。

41.什么情况下使用缓存?

答:当用户第一次访问应用系统的时候,因为还没有登录,会被引导到认证系统中进行登录;根据用户提供的登录信息,认证系统进行身份校验,如果通过校验,应该返回给用户一个认证的凭据--ticket;用户再访问别的应用的时候,就会将这个ticket带上,作为自己认证的凭据,应用系统接受到请求之后会把 ticket送到认证系统进行校验,检查ticket的合法性。如果通过校验,用户就可以在不用再次登录的情况下访问应用系统2和应用系统3了。

实现主要技术点:

    1、两个站点共用一个数据验证系统
    2、主要通过跨域请求的方式来实现验证及session处理。
Copy after login

42.怎么实现第三方登录?

答:第三方登陆主要是基于author协议来实现,下面简单说下实现流程:

1、首先我们需要以开发者的身份向第三方登陆平台申请接入应用,申请成功后,我们会获得一个appID和一个secrectID.
2、当我们的网站需接入第三方登陆时,会引导用户跳转到第三方的登陆授权页面,此时把之前申请的appID和secrectID带给登陆授权页面。
3、用户登陆成功后即得到授权,第三方会返回一个临时的code给我们的网站。
4、我们的网站接受到code后,再次向我们的第三方发起请求,并携带接收的code,从第三方获取access_token.
5、第三方处理请求后,会返回一个access_token给我们的网站,我们的网站获取到access_token后就可以调用第三方提供的接口了,比如获取用户信息等。最后把该用户信息存入到我们站点的数据库,并把信息保存到session中,实现用户的第三方登陆。
Copy after login

43.如何处理负载、高并发?(好好看看,经常问到,能回答到主要的东西即可)?

答:从低成本、高性能和高扩张性的角度来说有如下处理方案:

1、HTML静态化

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所支持的应用在这点上会比Nginx更多。在使用上,一般最前端所采取的策略应是LVS,也就是DNS的指向应为LVS均衡器,LVS的优点令它非常适合做这个任务。重要的ip地址,最好交由LVS托管,比如数据库的 ip、webservice服务器的ip等等,这些ip地址随着时间推移,使用面会越来越大,如果更换ip则故障会接踵而至。所以将这些重要ip交给 LVS托管是最为稳妥的,这样做的唯一缺点是需要的VIP数量会比较多。Nginx可作为LVS节点机器使用,一是可以利用Nginx的功能,二是可以利用Nginx的性能。当然这一层面也可以直接使用squid,squid的功能方面就比Nginx弱不少了,性能上也有所逊色于Nginx。Nginx也可作为中层代理使用,这一层面Nginx基本上无对手,唯一可以撼动Nginx的就只有lighttpd了,不过lighttpd目前还没有能做到 Nginx完全的功能,配置也不那么清晰易读。另外,中层代理的IP也是重要的,所以中层代理也拥有一个VIP和LVS是最完美的方案了。具体的应用还得具体分析,如果是比较小的网站(日PV小于1000万),用Nginx就完全可以了,如果机器也不少,可以用DNS轮询,LVS所耗费的机器还是比较多的;大型网站或者重要的服务,机器不发愁的时候,要多多考虑利用LVS。

数据库优化

44.做秒杀时锁表考虑到没有?

答:考虑到了,当时我们做秒杀时考虑了好几种方案,其中有一种就是使用事务加上排他锁来实现。

45.架构类的东西接触过吗?

有接触过,曾经自己在自己的服务器上配置过。我以前做过以下几个架构方面的配置和测试;

1、数据库的读写分离、主从复制及集群。
2、Nginx负载均衡
3、redis集群及主从
Copy after login

46.封装过一个简单的框架?

答;封装过一个简单的MVC框架,主要分为3层,控制器层和模型层视图层,以及路由的分配和入口文件,模板引擎,单例模式、工厂模式,第三方类库的引入等。

47.谈谈对MVC的认识?

答:核心思想是:视图和用户交互通过事件导致控制器改变 控制器改变导致模型改变 或者控制器同时改变两者 模型改变 导致视图改变 或者视图改变 潜在的从模型里面获得参数 来改变自己。他的好处是可以将界面和业务逻辑分离。

Model(模型),是程序的主体部分,主要包含业务数据和业务逻辑。在模型层,还会涉及到用户发布的服务,在服务中会根据不同的业务需求,更新业务模型中的数据。
View(视图),是程序呈现给用户的部分,是用户和程序交互的接口,用户会根据具体的业务需求,在View视图层输入自己特定的业务数据,并通过界面的事件交互,将对应的输入参数提交给后台控制器进行处理。
Contorller(控制器),Contorller是用来处理用户 输入数据,已经更新业务模型的部分。控制器中接收了用户与界面交互时传递过来的数据,并根据数据业务逻辑来执行服务的调用和更新业务模型的数据和状态。
Copy after login

48.session与cookie的区别?

1、cookie数据存放在第三方应用的浏览器上,session数据放在服务器上。

2、cookie不是很安全,别人可以分析存放在本地的COOKIE,进行COOKIE欺骗,考虑到安全应当使用session。

3、session会在一定时间内保存在服务器上。当访问增多,会比较占用你服务器的性能,考虑到减轻服务器性能方面,应当使用COOKIE。

4、单个cookie保存的数据不能超过4K,很多浏览器都限制一个站点最多保存20个cookie。

5、所以个人建议:
    将登陆信息等重要信息存放为SESSION
    其他信息如果需要保留,可以放在COOKIE
Copy after login

49.echo(),print(),print_r()的区别?

echo可以一次输出多个值,多个值之间用逗号分隔。echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用。echo是php的内部指令,不是函数,无返回值。

print():函数print()打印一个值(它的参数),如果字符串成功显示则返回true,否则返回false。只能打印出简单类型变量的值(如int,string),有返回值

printf():源于C语言中的printf()。该函数输出格式化的字符串。

print_r()和var_dump()
print_r()可以把字符串和数字简单地打印出来,而数组则以括起来的键和值得列表形式显示,并以Array开头。但print_r()输出布尔值和NULL的结果没有意义,因为都是打印"\n"。因此用var_dump()函数更适合调试。print_r是函数,可以打印出比较复杂的变量(如数组,对象),有返回值
var_dump()判断一个变量的类型与长度,并输出变量的数值,如果变量有值输的是变量的值并回返数据类型。此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。
Copy after login

50.说一下单引号双引号?

①单引号内部的变量不会执行, 双引号会执行

②单引号解析速度比双引号快。

③单引号只能解析部分特殊字符,双引号可以解析所有特殊字符。
Copy after login

51.索引的优缺点?

1、优点:

a)可以保证数据库表中每一行的数据的唯一性
b)可以大大加快数据的索引速度
c)加速表与表之间的连接,物别是在实现数据的参考完事性方面特别有意义
d)在使用分组和排序子句进行数据检索时,同样可以显著减少查询中分组和排序的时间
f)通过使用索引,可以在时间查询的过程中,使用优化隐藏器,提高系统的性能
Copy after login

2、 缺点:

a)  创建索引和维护索引要耗费时间,这种时间随着数据量的增加而增加
b)  索引需要占物理空间,除了数据表占用数据空间之外,每一个索引还要占用一定的物理空间,如果需要建立聚簇索引,那么需要占用的空间会更大
c)  以表中的数据进行增、删、改的时候,索引也要动态的维护,这就降低了整数的维护速度
d)  建立索引的原则
e)  在经常需要搜索的列上,可以加快搜索的速度
f)  在作为主键的列上,强制该列的唯一性和组织表中数据的排列结构
g)  在经常用在连接的列上,这些列主要是一外键,可以加快连接的速度
h)  在经经常需要根据范围进行搜索的列上创建索引,国为索引已经排序,其指定的范围是连续的
i)  在经常需要排序的列上,国为索引已经排序,这样井底可以利用索引的排序,加快排序井底时间
j)  在经常使用在where子句中的列上,加快条件的判断速度
Copy after login

52.get和post的区别?

1. get是从服务器上获取数据,post是向服务器传送数据。
2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
3. get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。
4. get安全性非常低,post安全性较高。但是执行效率却比Post方法好。
Copy after login

53.如何修改会话的生存时间?

一:在php.ini中设置session.gc_maxlifetime = 1440 //默认时间
二:代码实现      $ lifeTime = 24 * 3600; //保存一天
    session_set_cookie_params($ lifeTime); 
    在session_start();
Copy after login

54.Linux基本命令,目录结构?

arch显示机器的处理器架构
(1) uname -m显示机器的处理器架构
(2) uname -r显示正在使用的内核版本 
dmidecode -q显示硬件系统部件 - (SMBIOS / DMI)   
hdparm -i / dev / hda罗列一个磁盘的架构特性    
hdparm -tT / dev / sda在磁盘上执行测试性读取操作 
cat / porc / cpuinfo显示CPU信息 
cat / porc / interrupts显示中断
cat / porc / meminfo校验内存使用  
cat / porc / swaps显示哪些交换被使用 
cat / porc / verion显示内核的版本
cat /porc/net/dev 显示网络适配器及统计 
cat /porc/mounts 显示已加载的文件系统 

date 显示系统日期 
cal 2007 显示2007年的日历表 
date 041217002007.00 设置日期和时间 -月日时分年.秒 
clock -w 将时间修改保存到 BIOS 

文件搜索 
find / -name file1 从 '/'开始进入根文件系统搜索文件和目录 

locate \*.ps 寻找以 '.ps'结尾的文件 -先运行'updatedb'命令 
whereis halt 显示一个二进制文件、源码或man的位置 
which halt 显示一个二进制文件或可执行文件的完整路径 

挂载一个文件系统 
mount /dev/hda2 /mnt/hda2 挂载一个叫做hda2的盘- 确定目录'/ mnt/hda2' 已经存在 
umount /dev/hda2 卸载一个叫做hda2的盘- 先从挂载点'/ mnt/hda2' 退出 

追加命令

1,linux里把文件/etc/aaa中的内容追加到/usr/bbb中的内容的后面
  sudo cat /etc/aaa >>/usr/bbb
2,更改/etc/index.html的文件所有者为apache,文件群组为apache
  sudo chmod apache:apache  /etc/index.html
3,更改/etc/index.html的所有者权限为读取、写入、执行。群组权限为读取。其他权限为读取
  sudo chmod 744 /etc/index.html
4,删除/etc下名为hello的文件
  sudo rm /etc/index.html

当然,如果你是以orot用户执行以上操作,可以去掉前边的sudo!

df -hl 查看磁盘剩余空间

df -h 查看每个根路径的分区大小

du -sh [目录名] 返回该目录的大小

du -sm [文件夹] 返回该文件夹总M数

关机 (系统的关机、重启以及登出) 
shutdown -h now 关闭系统(1) 
init 0 关闭系统(2) 
telinit 0 关闭系统(3) 
shutdown -h hour:minutes & 按预定时间关闭系统 
shutdown -c 取消按预定时间关闭系统 
shutdown -r now 重启(1) 
reboot 重启(2) 
logout 注销

文件和目录 
pwd 显示工作路径 
ls 查看目录中的文件 
ls -F 查看目录中的文件 
ls -l 显示文件和目录的详细资料 
ls -a 显示隐藏文件 
ls *[0-9]* 显示包含数字的文件名和目录名 
tree 显示文件和目录由根目录开始的树形结构(1) 
lstree 显示文件和目录由根目录开始的树形结构(2) 
mkdir dir1 创建一个叫做 'dir1'的目录' 

磁盘空间 
df -h 显示已经挂载的分区列表 
ls -lSr |more 以尺寸大小排列文件和目录 
du -sh dir1 估算目录 'dir1'已经使用的磁盘空间' 

下载、解压

1)对于.tar结尾的文件 
  tar -xf all.tar 

2)对于.gz结尾的文件 
  gzip -d all.gz 
  gunzip all.gz 

# zip all.zip *.jpg 
  这条命令是将所有.jpg的文件压缩成一个zip包 
# unzip all.zip 
  这条命令是将all.zip中的所有文件解压出来

下载命令

wget + 空格 +要下载文件的url路径

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

Shell 脚本:

必须以  #!/bin/sh  开头

简单例子:判断这个目录下有没有文件(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  这个命令能够统计文件个数 为0就是没有文件 非零就是有文件
Copy after login

55..memcache缓存什么数据?

一、经常被读取并且实时性要求不强可以等到自动过期的数据。例如网站首页最新文章列表、某某排行等数据。
二、经常被读取并且实时性要求强的数据。比如用户的好友列表,用户文章列表,用户阅读记录等。
三、统计类缓存,比如文章浏览数、网站PV等。
四、活跃用户的基本信息或者某篇热门文章。
五、session数据
Copy after login

56.魔术方法、魔术常量?

1。__construct()
实例化对象时被调用,当__construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用。
2。__destruct()
当删除一个对象或对象操作终止时被调用。
3。__call()
对象调用某个方法,若方法存在,则直接调用;若不存在,则会去调用__call函数。
4。__get()
读取一个对象的属性时,若属性存在,则直接返回属性值;若不存在,则会调用__get函数。
5。__set()
设置一个对象的属性时,若属性存在,则直接赋值;若不存在,则会调用__set函数。
6。__toString()
打印一个对象的时被调用。如echo $obj;或print $obj;
7。__clone()
克隆对象时被调用。如:$t=new Test();$t1=clone $t;
8。__sleep()
serialize之前被调用。若对象比较大,想删减一点东东再序列化,可考虑一下此函数。
9。__wakeup()
unserialize时被调用,做些对象的初始化工作。
10。__isset()
检测一个对象的属性是否存在时被调用。如:isset($c->name)。
11。__unset()
unset一个对象的属性时被调用。如:unset($c->name)。
12。__set_state()
调用var_export时,被调用。用__set_state的返回值做为var_export的返回值。
13。__autoload()
实例化一个对象时,如果对应的类不存在,则该方法被调用。
Copy after login

魔术常量:

__LINE__
返回文件中的当前行号。

__FILE__
返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。

__FUNCTION__
返回函数名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在PHP 4 中该值总是小写字母的。

__CLasS__
返回类的名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该类被定义时的名字(区分大小写)。在PHP 4 中该值总是小写字母的。

__METHOD__
返回类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。

__set()当程序试图写入一个不存在或者不可见的成员变量时,__set()方法包含两个参数,分别表示变量名称和变量值,两个参数都不可省略

__get()当程序试图调用一个未定义或不可见的成员变量时,__get()方法有一个参数,表示要调用的变量名

__sleep() 常用于提交未提交的数据,或类似的清理操作如果有一些很大的对象,但不需要全部保存,这个功能就很好用。

__construct()  在类实例化对象的同时执行该函数

__distruct() 在类实例化的对象销毁时执行

__call()对象调用某个方法,若方法存在,则直接调用;若不存在,则会去调用__call函数。

__clone()克隆对象时被调用。如:$t=new Test();$t1=clone $t;

__toString()打印一个对象的时被调用。如echo $obj;或print $obj;

__isset()检测一个对象的属性是否存在时被调用。如:isset($c->name)。

__unset()unset一个对象的属性时被调用。如:unset($c->name)。

__autoload()实例化一个对象时,如果对应的类不存在,则该方法被调用。
Copy after login

57.接口和抽象类的区别是什么?

答:抽象类是一种不能被实例化的类,只能作为其他类的父类来使用。抽象类是通过关键字abstract来声明的。 

抽象类与普通类相似,都包含成员变量和成员方法,两者的区别在于,抽象类中至少要包含一个抽象方法,抽象方法没有方法体,该方法天生就是要被子类重写的。 

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

接口是通过 interface 关键字来声明的,接口中的成员常量和方法都是 public 的,方法可以不写关键字public,接口中的方法也是没有方法体。接口中的方法也天生就是要被子类实现的。 

抽象类和接口实现的功能十分相似,最大的不同是接口能实现多继承。在应用中选择抽象类还是接口要看具体实现。 

子类继承抽象类使用 extends,子类实现接口使用implements。

58.什么是队列?排它锁,Myisam死锁如何解决?

答:在默认情况下MYisam是表级锁,所以同时操作单张表的多个动作只能以队列的方式进行;

排它锁又名写锁,在SQL执行过程中为排除其它请求而写锁,在执行完毕后会自动释放;

死锁解决:先找到死锁的线程号,然后杀掉线程ID

59.bootstrap框架有哪些优点?

答:bootstrap是一款web开发框架,它由CSS,JavaScript,Html,三部分构成,它简洁灵活,使得web开发更加的快捷

优点: 

① 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

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template