search
HomeBackend DevelopmentPHP Tutorial 百度PHP电话面试之10问

百度PHP电话面试之十问

【本文来自】http://www.16nn.com/?p=309 


小结,百度的面试,尤其是初面,最看重的就是基础,基础,还是基础。涉及的面比较广,但都是一个程序员应当也应该知道的东东。回过头来重新找资料做了下题目,答案仅供参考。


1、PHP的整型溢出问题是怎样的
2、如何理解OOP
3、你对于设计模式和MVC的理解
4、HTTP协议1.0及1.1的区别,并简单说下HTTP协议
5、简单说下Apache中rewrite机制和PHP框架中URI路由机制
6、MySQL的索引机制,复合索引的使用原则
7、MySQL的表类型及MyISAM与InnoDB的区别
8、简单说下快速排序算法
9、awk、sed、sort的基本使用(用实例考察的)
10、Memcached、redis的使用和理解


================================================
【1】PHP的整型溢出问题是怎样的


  PHP的整型数的字长和平台有关,对于32位的操作系统,最大的整型是有二十多亿,其实就是2的31次方,最小为-2的31次方,PHP不支持无符号的整数。 如果一个数超出了integer范围,将会被自动解释为float。如果执行的运算结果超出了 integer 范围,也会返回 float。(那在java、C中的整型整型溢出会怎样)


【2】如何理解OOP


  OOP,面向对象编程,包括三个方面,继承性、封装性、多态性,其中最根本的东西就是抽象。
  继承性,即扩展性,通过子类对已经存在的父类进行功能扩展。
  封装性,要求外部不能随意存取对象的内部数据,即对该类中的具体实现做封装,用户不必知道内部的具体实现,只有知道它是干什么的,怎么用就好了。
  多态性,就是类的抽象和接口,同一个类能够处理多种类型对象的能力。


  我们在现实中,看到的任何东东都可以看做为一个对象,然后通过进一步的抽象为类,类又可以演变为很多类似的对象。举个简单的例子,将我们看到的一个房子抽象为一个ROOM类,包括基本的门,窗,桌子等物件,人可以进出等功能。 现在我们继承ROOM类为Classroom,包括扇门,有大窗,有桌椅,另外只包括一个黑白和一个讲台,老师和同学可以上课。现在我们实例化这个Classroom类为Classroom_621对象,包括两扇门,四扇大窗,30套桌椅,有同学正在上毛概课。


【3】你对于设计模式和MVC的理解


Model-View-Controller,模型、视图、控制器,一想到MVC就会想到JAVA,因为JAVA是一个完全面向对象的语言,MVC最早出现在smalltalk中,其核心就是要将试图和数据模型分离,这样不同的程序就可以有不同的展示。


模型,即程序员写的功能、算法和数据模型,也就是我们说的系统业务逻辑层。
试图,即前端,图形界面。展示给用户看的。
控制器,主要负责对请求处理和转发。


设计模式,其实就是代码的设计经验的总结和归类,设计模式最早应用与建筑行业,编程的设计模式按最早的GoF所述,包括23种设计模式,主要用于面向对象的程序编程。遵循几个设计原则:开闭原则、单一职责原则、里氏替换原则、依赖注入、接口分离、迪米特原则、优先使用组合而不是继承等等。包括创建型模式、结构性模式、行为模式三类。


【4】HTTP协议1.0及1.1的区别,并简单说下HTTP协议


HTTP,超文本传输协议。它定义了浏览器和服务器的通信规则。HTTP协议是基于TCP/IP的TCP协议上,现在万维网使用的是HTTP1.1版本,其特点包括,C/S模式,请求简单(GET/POST/HEAD),灵活(可以传输任何类型的数据HTML、XML、JSON、自定义等),无连接(每次连接只处理一个请求,从发出请求到收到200状态为止断开连接),无状态。


HTTP协议主要包括,响应消息格式、请求消息格式、状态码知识点。


[响应消息格式]
HTTP/1.1 200 0K
Connectlon:close
Date: Thu, 13 Oct 2005 03:17:33 GMT
Server: Apache/2.0.54 (Unix)
Last―Nodified:Mon,22 Jun 1998 09;23;24 GMT
Content―Length:682l
Content―Type:text/html


这个响应消息分为3部分:1个起始的状态行(status line),6个头部行、1个包含所请求对象本身的附属体。状态行有3个字段:协议版本字段、状态码字段、原因短语字段。


[请求消息格式]
GET /somedir/page.html HTTP/1.1
Host:www.chinaitlab.com
Connection:close
User-agent:Mozilla/4.0
Accept-language:zh-cn
(额外的回车符和换行符)


该请求消息的第一行称为请求行 (request line),后续各行都称为头部行(header)。请求行有3个字段:方法字段、URL字段、HTTP版本字段。


[状态码]参见http://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html
1xx 消息
2xx 成功
3xx 重定向
4xx 请求错误
5xx 服务器错误


200 OK。请求已成功,请求所希望的响应头或数据体将随此响应返回。


301 Moved Permanently。表示请求的网页已永久转移到新位置
302 Found。表示页面在做临时跳转时返回的状态。
303 Not Modified。客户的缓存资源是最新的, 要客户端使用缓存。


403 Forbidden。请求被服务器拒绝了。
404 Not Found。表示服务器找不到请求的网页,服务器上不存在的网页经常会返回的HTTP状态码。


500 Internal Server Error。
503 Service Unavailable。服务器目前无法为请求提供服务,但过一段时间就可以恢复服务。
504 Gateway Timeout。与状态吗408类似, 但是响应来自网关或代理,此网关或代理在等待另一台服务器的响应时出现了超时。


【5】简单说下Apache中rewrite机制和PHP框架中URI路由机制
   
1)URL重写,其实就是把用户通过浏览器请求的URL,到了后台,apache根据预先配置的重写规则将该请求指向真正的资源路径,说白了就是打马虎眼,把真正的路径改头换面后给用户访问,可问题是这样做有啥用处。
1、SEO方面。将动态的URL静态化,以满足搜索引擎的胃口。
2、访问控制。比如,通过重写规则后,客户端不易判断后台程序类型等。
3、URL重定向。当网站更改域名或增加别名URL后,可以通过规则轻松的指向要访问的URL。


 http://httpd.apache.org/docs/current/mod/mod_rewrite.html    
    mod_rewrite 使用基于正则表达式动态的修改传入请求的URL。它可以将URL映射到文件系统路径,也可以将一个URL映射到另一个URL。它使用了没有限制数量的规则来操纵URL,每条规则可以包括没有限制数量的附加条件。你可以通过多种方式来检测,如,服务器变量、环境变量、HTTP头、时间戳等。
    mod_rewrite 操作整个URL路径,包括path-info的部分。一个重写规则可以被设置在http.conf或者.htaccess中。一个重写规则生成的路径可以包括一个请求字符串,或者内部的子程序处理,外部请求的重定向,或者穿透内部代理等。


2)PHP框架中的URI路由机制,与apache重写类似,一般包括通配符和正则两种规则。让用户可以重新定向(remap)URI处理程序. 设定你自己的路由规则。


【6】MySQL的索引机制,复合索引的使用原则


(深入浅出MySQL一书中对索引的使用讲的比较细致) 
一般都会用书本中的目录来介绍索引机制,其实有些书本会有专门的快速检索附录,就很类似于数据库的索引。
MySQL的索引包括4类:主键索引(primary key)、唯一索引(unique)、常规索引(index)、全文索引(fullindex)。 Show index from table_name; --查看表中的索引
Show status like 'Handler_read%'  --查看索引的使用情况


复合索引,一般遵循最左前缀原则,如table_a 的 a b c 三列建复合索引 
create index ind_table_a on table_a(a,b,c);
那么,只有在条件中用到a,或者a、b,或者a、b、c这样的情况下,才会用到刚建的复合索引。


【7】MySQL的表类型及MyISAM与InnoDB的区别


MySQL常见的表类型(即存储引擎)show engines包 括:MyISAM/Innodb/Memory/Merge/NDB


其中,MyISAM和Innodb是最常用的两个表类型,各有优势,我们可以根据需求情况选择适合自己的表类型。
[MyISAM]
1)每个数据库存储包括3个文件:.frm(表定义)、MYD(数据文件)、MYI(索引文件)
2)数据文件或索引文件可以指向多个磁盘
3)Linux的默认引擎,win默认InnoDB
4)面向非事务类型,避免事务型额外的开销
5)适用于select、insert密集的表
6)MyISAM默认锁的调度机制是写优先,可以通过LOW_PRIORITY_UPDATES设置
7)MyISAM类型的数据文件可以在不同操作系统中COPY,这点很重要,布署的时候方便点。


[Innodb]
1)用于事务应用程序
2)适用于update、delete密集的操作。执行select count(*) from table时,InnoDB要扫描一遍整个表来计算有多少行,但是MyISAM只要简单的读出保存好的行数即可。注意的是,当count(*)语句包含 where条件时,两种表的操作是一样的。DELETE FROM table时,InnoDB不会重新建立表,而是一行一行的删除。
3)引入行级锁和外键的约束
4)InnoDB不支持FULLTEXT类型的索引


【8】简单说下快速排序算法


基本思想:通过一趟排序将待排序列分割成两部分,其中一部分比另一部分记录小,再分别对这两部分继续快速排序,以达到有序。
算法实现:设有两个指针low和high,初值为low=1,high=n,设基准值为key(通常选第一个),则首先从high位置开始向前搜索,找到第一个比key小的记录与key交换,然后从low位置向后搜索,找到第一个比key大的记录与基准值交换,重复直至low=high为止。


第一趟排序结果,key之前的记录值比key之后的记录值小。


11 25 9  3  16 2   //选择11为key
2  25 9  3  16 11
2  11 9  3  16 25
2  3  9  11 16 25


【9】awk、sed、sort的基本使用(用实例考察的)


[例]:有如下文件test,请统计每个网址出现次数,用一句shell实现。
a www.baidu.com 20:00
b www.qq.com 19:30
c www.baidu.com 14:00
d www.baidu.com 23:00
e www.qq.com 20:30
f www.360.com 20:30


cat test| awk -F' ' '{print $2}' |sort -n |uniq -c


【10】Memcached、redis的使用和理解
   Memcached和redis 都是一个key-value的内存式存储系统,通过hash表来存储检索结果,做到强大的缓存机制。像新浪的微博、淘宝等大流量站点都必须的使用了这些东东。
    下面是从百科中摘录的介绍。具体实践和使用后续再详细介绍。
    Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
    redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。
Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

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

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software