腾讯PHP工程师笔试题.doc_第1页
腾讯PHP工程师笔试题.doc_第2页
腾讯PHP工程师笔试题.doc_第3页
腾讯PHP工程师笔试题.doc_第4页
腾讯PHP工程师笔试题.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 请对POSIX风格和兼容Perl风格两种正则表达式的主要函数进行类比说明ereg preg_matchereg_replace preg_replace2 请说明在php.ini中safe_mode开启之后对于PHP系统函数的影响3 PHP5中魔术方法函数有哪几个,请举例说明各自的用法_sleep_wakeup_toString_set_state_construct,_destruct_call,_get,_set,_isset,_unset_clone_autoload4 请写出让,并说明如何在命令行下运行PHP脚本(写出两种方式)同时向PHP脚本传递参数?5 PHP的垃圾收集机制是怎样的6使对象可以像数组一样进行foreach循环,要求属性必须是私有。(Iterator模式的PHP5实现,写一类实现Iterator接口)7请写一段PHP代码,确保多个进程同时写入同一个文件成功8 用PHP实现一个双向队列9 使用正则表达式提取一段标识语言(html或xml)代码段中指定标签的指定属性值(需考虑属性值对不规则的情况,如大小写不敏感,属性名值与等号间有空格等)。此处假设需提取test标签的attr属性值,请自行构建包含该标签的串10请使用socket相关函数(非curl)实现如下功能:构造一个post请求,发送到指定http server的指定端口的指定请求路径(如:8080/test)。请求中包含以下变量:用户名(username):温柔一刀密码(pwd):&123=321&321=123&个人简介(intro):Hello world!且该http server需要以下cookie来进行简单的用户动作跟踪:cur_query:you&melast_tm:.(上次请求的unix时间戳,定为当前请求时间前10分钟)cur_tm:.(当前请求的unix时间戳)设置超时为10秒,发出请求后,将http server的响应内容输出。1. Function encode($data, $sep = ‘’) 2. while (list($k,$v) = each($data) 3. $encoded .= ($encoded ? $sep : ); 4. $encoded .= rawurlencode($k).=.rawurlencode($v); 5. 6. Return $encoded; 7. 8. 9. Function post($url, $post, $cookie) 10. $url = parse_url($url); 11. $post = encode($data, ‘’); 12. $cookie = encode($cookieArray, ‘’); 13. $fp = fsockopen($urlhost, $urlport ? $urlport : 80, $errno, $errstr, 10); 14. if (!$fp) return Failedto open socket to $urlhost; 15. 16. fputs($fp, sprintf(POST %s%s%sHTTP/1.0n, $urlpath, $urlquery ? ? : , $urlquery); 17. fputs($fp, Host: $urlhostn); 18. fputs($fp, Content-type: application/x-www-form-urlencodedn); 19. fputs($fp, Content-length: . strlen($encoded) . n); 20. fputs($fp, Cookie: $cookienn); 21. fputs($fp, Connection: closenn); 22. fputs($fp, $post n); 23. 24. while (!feof($fp) 25. echo fgets($fp, 128); 26. 27. fclose($fp); 28. 29. 30. $url = ‘:8080/test’ 31. $encoded = username=温柔一刀& pwd= 32. $post = array( 33. ‘username’= ‘温柔一刀’, 34. ‘pwd = ‘&123=321&321=123’, 35. ‘intro = ‘Hello world!’ 36. ); 37. $cookie = array( 38. ‘cur_query’ = ‘you&me, 39. ‘last_tm’ = time() - 600, 40. ‘cur_tm ‘= time() 41. ); 42. 43. Post($url, $post, $cookie); 44. ?11你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在?1脚本执行时间,启用xdebug,使用WinCacheGrind分析。2数据库查询,mysql使用EXPLAIN分析查询,启用slow query log记录慢查询。PHP LAMP Engineer Test Paper Question 1What does print out?A) 3B) FalseC) NullD) 1E) 0Question 2Which of the following snippets prints a representation of 42 with two decimal places?A) printf(%.2dn, 42);B) printf(%1.2fn, 42);C) printf(%1.2un, 42);Question 3Given$text = Content-Type: text/xml;Which of the following prints text/xml?A) print substr($text, strchr($text, :);B) print substr($text, strchr($text, :) + 1);C) print substr($text, strpos($text, :) + 1);D) print substr($text, strpos($text, :) + 2);E) print substr($text, 0, strchr($text, :)Question 4What is the value of $a?A) TrueB) FalseQuestion 5What is the value of $result in the following PHP code?;Answer: NULLQuestion 6The code below _ because _.A) will work, class definitions can be split up into multiple PHP blocks.B) will not work, class definitions must be in a single PHP block.C) will not work, class definitions must be in a single file but can be in multiple PHP blocks.D) will work, class definitions can be split up into multiple files and multiple PHP blocks.Question 7When turned on, _ will _ your script with different variables from HTML forms and cookies.A) show_errors, enableB) show_errors, showC) register_globals, enhanceD) register_globals, injectQuestion 8What will be the output of the following PHP code:Answer: 1Question 9What is the best all-purpose way of comparing two strings?A) Using the strpos functionB) Using the = operatorC) Using strcasecmp()D) Using strcmp()Question 10What is the difference between print() and echo()?Answer: print is a function,echo is a language construct附文章源产地管理员的答案:附:1. 看手册2. 【PHP安全几则tips】1. 输入输出安全(1)关闭 register_global 选项(php4及以前),初始化所有变量,能防止调用未定义变量notice错误,也能够防范一些hacker行为(2)接收任何变量的时候,务必记住:所有用户输入都是不安全的!如果确定用户输入数据是整数(比如ID之类),可以使用(int)或intval()函数强制类型转换,如果是字符串类型,使用 addslashes 或 mysql_escape_string(如果考虑数据库编码请连接数据库后使用mysql_real_escape_string更安全,针对GBK等编码,使用该函数能够防范目前很多GBK编码爆出的注入漏洞)注1 (3)输出数据的时候,如果害怕html,可以使用strip_tags全部过滤,或者使用 htmlspecialchars 进行html标签转义保证输出到页面不会构成威胁,另外,最好输入或者输出的时候过滤所有的等标记和内容,有时候或作为属性的style也最好过滤一下注1:问题来自多字节编码。例如在GBK里,0xbf27并不是一个合法的双字节字符,因此addslash()会把它转义成0xbf5c27,碰巧0xbf5c是一个合法的双字节字符,由此可以注入一个0x27 ()。addslash()和mysql_escape_string无药可救。mysql_real_escape_string()可以根据字符集正确地转义,但是需要在建立数据库联接的时候指明“SET CHARACTER SET GBK”。2. php系统安全(1)打开 safe_mode 是最重要的,同时设置 open_basedir, safe_mode_include_dir,safe_mode_exec_dir 等选项(2)当要操作或者包含文件的时候,使用realpath 和 basename 检查文件是否是本地文件(3)如果很多危险函数如果不使用,建议关闭,关闭函数修改disbale_functions选项,比如很多命令执行函数、eval、phpinfo 等函数(4)如果不需要上传文件功能可以关闭,如果需要记得设置 post_max_size 选项为你合适的大小,否则文件系统很容易被塞满,并且move_uploaded_file来操作上传的文件,而且不是使用copy(5)把库文件(.inc)和数据文件(数据信息,配置信息,sqlite数据库等)不要与web目录放在一起,防止被下载3. 看手册4. 头上写 #!/usr/bin/php 或者 /usr/bin/php xxxx.php5. 写时复制,引用为0时回收,参考这几个帖子:/viewthread.php?tid=342&extra=page%3D1/viewthread.php?tid=288/viewthread.php?tid=2896. 迭代器设计模式的实现,参考这个帖子:/viewthread.php?tid=365property = get_object_vars($obj); function reset() reset($this-property); function end() end($this-property); function current() return current($this-property); function next() return next($this-property); function prev() return prev($this-property); function each() return each($this-property); /测试代码class test var $var1 = 1; var $var2 = 2; var $var3 = 3; var $var4 = 4; function test()$obj = new test; foreach($obj as $k=$v) echo $k = $vn;$iterator = new ObjIterator($obj);$iterator-reset();while($s = $iterator-each() print_r($s);7. 多进程写文件,参考这个帖子:/viewthread.php?tid=344通过php中的 pcnl_* 函数来生成多进程操作同一个文件?phpfunction writefile($file, $pid) static $count; $count+; echo call writefile, pid=$pid, count=$countn; while(1) $fp = fopen($file, a+); if(!$fp) /usleep(rand(100,1000); continue; break; while(1) if(!flock($fp, LOCK_EX) /usleep(rand(100,1000); /usleep(1000); continue; fwrite($fp, PID: $pidtTest contents.$count.n); flock($fp, LOCK_UN); fclose($fp); break; return;echo Start .n;unlink(./fork_test3.txt);for($i=0; $i5; $i+) $pid = pcntl_fork(); switch($pid) case -1: die(fork error);break; case 0: writefile(./fork_test3.txt, po

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论