和百度面试官约好了时间,进行了我的第一次电话面试,面试的职位是PHP开发。下面我概要讲述一下面试官的问题所涉及的面,希望自己从中吸取教训和获得新的知识,也希望能给其他正在找工作的同仁提供些参考。
问题一:PHP的基础知识
require和include函数之间的区别,我上网查了一下,比如这个链接(http://www.cnblogs.com/xia520pi/p/3697099.html)里面就有详细的关于require和include的区别。但经过我的测试以后,是不是PHP版本之间的问题,我的PHP版本是5.4的,有些区别是不存在的。主要的区别是,当前脚本在使用include和require函数引用一个文件时,如果这个文件不存在时,include产生一个warning级别的错误,并继续执行当前脚本的代码;而require同时产生warning和Fatal error的错误,并结束当前脚本的执行。
__autoload()和spl_autoload_register()自动加载类函数的使用。
__autoload()自动加载类:
spl_autoload():
- <?php
- set_include_path('include' . PATH_SEPARATOR . get_include_path());
- spl_autoload_extensions('.php'); //加载的文件扩展名
- spl_autoload('Cat');
- spl_autoload('Dog');
- $cat = new Cat();
- $dog = new Dog();
- ?>
spl_autoload_register():
- <?php
- set_include_path('include' . PATH_SEPARATOR . get_include_path());
- spl_autoload_extensions('.php'); //加载的文件扩展名
- spl_autoload_register(); //默认注册的是spl_autoload()函数
- /*或 spl_autoload_register(function($class_name){
- include 'include/' . strtolower($class_name) . '.php';
- });*/
- $cat = new Cat();
- $dog = new Dog();
- ?>
- <?php
- set_include_path('include' . PATH_SEPARATOR . get_include_path());
- function __autoload($class_name)
- {
- include $class_name . 'php';
- }
- function my_autoload($class_name)
- {
- include $class_name . '.php';
- }
- spl_autoload_register('my_autoload');
- print_r(spl_autoload_functions());
- /*
- spl_autoload_functions()的结果为:Array ( [0] => my_autoload )
- spl_autoload_functions()表示其函数队列中注册的函数是my_autoload
- 前面定义的__autoload()失效了,因为autoload_func函数指针已指向spl_autoload方法
- If your code has an existing __autoload() function then this function
- must be explicitly registered on the __autoload queue.This is because
- spl_autoload_register() will effectively replace the engine cache for
- the __autoload() function by either spl_autoload() or spl_autoload_call().
- 这是官方手册关于spl_autoload_register的一句描述,估计表示的就是这个意思
- */
- $cat = new Cat();
- $dog = new Dog();
- echo '<br />';
- spl_autoload_register( '__autoload' ); //把 _autoload 方法加入 autoload_functions list
- print_r(spl_autoload_functions());
- /*
- spl_autoload_functions()的结果为:Array ( [0] => my_autoload [1] => __autoload )
- 这也说明自动加载函数只能定义一次
- */
- ?>
问题二:PHP运行方式
http://blog.youkuaiyun.com/hguisu/article/details/7386882 问题三:HTTP协议
2xx:成功--表示请求已被成功接收、理解、接受
3xx:重定向--要完成请求必须进行更进一步的操作
4xx:客户端错误--请求有语法错误或请求无法实现
5xx:服务器端错误--服务器未能实现合法的请求
200 OK //客户端请求成功
400 Bad Request //客户端请求有语法错误,不能被服务器所理解
401 Unauthorized //请求未经授权,这个状态代码必须和WWW-Authenticate报头域一起使用
403 Forbidden //服务器收到请求,但是拒绝提供服务
404 Not Found //请求资源不存在,eg:输入了错误的URL
500 Internal Server Error //服务器发生不可预期的错误
503 Server Unavailable //服务器当前不能处理客户端的请求,一段时间后可能恢复正常
问题四:跨域请求数据
问题五:MySQL索引
索引有两种存储类型,包括B型树(BITREE)索引和哈希(HASH)索引,InnoDB和MyISAM存储引擎支持BITREE索引,MEMORY存储引擎支持HASH索引和BITREE索引。MySQL索引包括普通索引、唯一性索引(UNIQUE)、全文索引(FULLTEXT,对于字段类型是char、varchar、text等类型)、单列索引、多列索引、空间索引(SPATIAL)等。使用多列索引时,如果没有使用索引中的第一个字段,那么这个多列索引不会起作用。
索引设计原则:
1、选择唯一性索引,不重复字段
2、为经常需要排序、分组和联合操作的字段建立索引,比如经常需要ORDERBY、GROUP BY、DISTINCT和UNION等操作的字段。
3、为常作为查询条件的字段建立索引
4、限制索引的数目,每个索引都需要占用磁盘空间,索引越多,需要的磁盘空间就越大
5、尽量使用数据量少的索引,比如对一个char(100)和char(10)的字段建立全文索引,检索char(10)的效率肯定会好很多
6、尽量使用前缀来索引,比如TEXT和BLOG类型的字段,进行全文索引会很浪费时间,如果只检索字段的前面若干个字节,这样可以提高检索速度
7、删除不再使用或者很少使用的索引
创建索引:
方式一:创建表时创建索引,
- create table 表名(
- 属性名 数据类型 [完整性约束条件],
- 属性名 数据类型 [完整性约束条件],
- ……
- 属性名 数据类型 [完整性约束条件],
- [unique|fulltext|spatial] index|key [<span style="font-family:Microsoft YaHei;">索引</span>名] (属性名1 [索引长度] [asc|desc])
- );
- create table index_test(
- id int,
- subject varchar(30),
- index subject_index (subject(10)) #subject_index索引的长度为10,对于字符串的数据,不用查询全部信息,而只查询前面的若干字符信息即可
- );
- mysql> show create table index_test\G
- *************************** 1. row ***************************
- Table: index_test
- Create Table: CREATE TABLE `index_test` (
- `id` int(11) DEFAULT NULL,
- `subject` varchar(30) DEFAULT NULL,
- KEY `subject_index` (`subject`(10))
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
- 1 row in set (0.00 sec)
- create [unique|fulltext|spatial] index 索引名 on 表名(属性名 [索引长度] [asc|desc]);
- alter table 表名 add [unique|fulltext|spatial] index 索引名(属性名 [索引长度] [asc|desc]);
删除索引:
- drop index 索引名 on 表名;
问题六:Top k 问题,数据排序
海量日志数据,提取出某日访问百度次数最多的那个IP,
参考结构之法july的博客http://blog.youkuaiyun.com/v_JULY_v/article/details/6279498
掌握堆排序、快速排序等排序算法。
问题七:讲述你做的项目
讲述做过的项目,这个照实讲就行了,让面试官明白项目不是虚构的,是真正做过的。