XBOX

  PHP博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  13 随笔 :: 87 文章 :: 0 评论 :: 0 Trackbacks

1.  请对POSIX风格和兼容Perl风格两种正则表达式的主要函数进行类比说明

ereg

preg_match

ereg_replace

preg_replace

 

2.  请说明在php.inisafe_mode开启之后对于PHP系统函数的影响

   

3.  PHP5中魔术方法函数有哪几个,请举例说明各自的用法

lzy © 2008, View php source
  1.  
  2. __sleep
  3. __wakeup
  4. __toString
  5. __set_state
  6. __construct,
  7. __destruct
  8. __call,
  9. __get,
  10. __set,
  11. __isset,
  12. __unset
  13. __sleep,
  14. __wakeup,
  15. __toString,
  16. __set_state,
  17. __clone
  18. __autoload
  19.  
Parsed in 0.033 seconds

 

4.  请写出让,并说明如何在命令行下运行PHP脚本(写出两种方式)同时向PHP脚本传递参数?

 

lzy © 2008, View php source
  1.  
  2. 1. Php filename.php $agr1 $agr2
  3. 2. php –r “”
  4.  
Parsed in 0.027 seconds

 

 

5.  PHP的垃圾收集机制是怎样的

 

6.使对象可以像数组一样进行foreach循环,要求属性必须是私有。

(Iterator模式的PHP5实现,写一类实现Iterator接口)

 

7.请写一段PHP代码,确保多个进程同时写入同一个文件成功

 

8.  PHP实现一个双向队列

 

9.  使用正则表达式提取一段标识语言(htmlxml)代码段中指定标签的指定属性值(需考虑属性值对不规则的情况,如大小写不敏感,属性名值与等号间有空格等)。此处假设需提取test标签的attr属性值,请自行构建包含该标签的串

 

<test attr=”ddd”>

 

<test attrs*=s*[“|’](.*?)[”|’].*?>

 

10.请使用socket相关函数(非curl)实现如下功能:构造一个post请求,发送到指定http server的指定端口的指定请求路径(如http://www.example.com:8080/test)。请求中包含以下变量

 

用户名(username):温柔一刀

密码(pwd):&123=321&321=123&

个人简介(intro):Hello world!

 

且该http server需要以下cookie来进行简单的用户动作跟踪:

 

cur_queryyou&me

last_tm...(上次请求的unix时间戳,定为当前请求时间10分钟)

cur_tm...(当前请求的unix时间戳)

 

设置超时为10秒,发出请求后,将http server的响应内容输出。

 

lzy © 2008, View php source
  1.  
  2. Function encode($data, $sep = &lsquo;&&rsquo;){
  3. while (list($k,$v) = each($data)) {
  4. $encoded .= ($encoded ? "$sep" : "");
  5. $encoded .= rawurlencode($k)."=".rawurlencode($v);
  6. }
  7. Return $encoded;
  8. }
  9. Function post($url, $post, $cookie){
  10. $url = parse_url($url);
  11. $post = encode($data, '&');
  12. $cookie = encode($cookieArray, ';');
  13. $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10);
  14. if (!$fp) return "Failed to open socket to $url[host]";
  15. fputs($fp, sprintf("POST %s%s%s HTTP/1.0 ", $url['path'], $url['query'] ? "?" : "", $url['query']));
  16. fputs($fp, "Host: $url[host] ");
  17. fputs($fp, "Content-type: application/x-www-form-urlencoded ");
  18. fputs($fp, "Content-length: " . strlen($encoded) . " ");
  19. fputs($fp, "Cookie: $cookie ");
  20. fputs($fp, "Connection: close ");
  21. fputs($fp, "$post ");
  22.  
  23. while (!feof($fp)) {
  24. echo fgets($fp, 128);
  25. }
  26. fclose($fp);
  27. }
  28. $url = 'http://www.example.com:8080/test';
  29. $encoded = username=温柔一刀& pwd=
  30. $post = array(
  31. 'username'=> '温柔一刀',
  32. 'pwd => '&123=321&321=123&',
  33. 'intro'=> 'Hello world!'
  34. );
  35. $cookie = array(
  36. 'cur_query' => 'you&me',
  37. 'last_tm' => time() - 600,
  38. 'cur_tm '=> time()
  39. );
  40. Post($url, $post, $cookie);
  41.  
Parsed in 0.485 seconds

 

 

11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在?

1.脚本执行时间,启用xdebug,使用WinCacheGrind分析。

2.数据库查询,mysql使用EXPLAIN分析查询,启用slow query log记录慢查询。

posted on 2008-12-01 14:47 XBOX 阅读(177) 评论(0)  编辑 收藏 引用 网摘 所属分类: PHP

只有注册用户登录后才能发表评论。
网站导航: