PHP LAMP Engineer Test Paper
Question 1
What does <? echo count ("123") ?> print out?
A) 3
B) False
C) Null
D) 1
E) 0Question 2
Which of the following snippets prints a representation of 42 with two decimal places?
A) printf("%.2d\n", 42);
B) printf("%1.2f\n", 42);
C) printf("%1.2u\n", 42);Question 3
Given
    $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 4
What is the value of $a?
    <?php
        $a = in_array('01', array('1')) == var_dump('01' == 1); 
    ?>
A)  True
B)  False
Question 5
What is the value of $result in the following PHP code?
    <?php
        function timesTwo($int) {
            $int = $int * 2;    
        }
        $int = 2;
        $result = timesTwo($int);
    ?>;
Answer: NULL
Question 6
The code below ___________ because ____________.
<?php
    class Foo {
    ?>
    <?php
           function bar() {
               print "bar";
           }
    }
?>
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 7
When turned on, ____________ will _________ your script with different variables from HTML forms and cookies.
A) show_errors, enable
B) show_errors, show
C) register_globals, enhance
D) register_globals, inject 
Question 8
What will be the output of the following PHP code:
    <?php
        echo count(strlen("http://php.net"));
    ?>
Answer: 1
Question 9
What is the best all-purpose way of comparing two strings?
A) Using the strpos function
B) Using the == operator
C) Using strcasecmp()
D) Using strcmp() 
Question 10
What is the difference between "print()" and "echo()"?
Answer: print is a function,echo is a language construct

解决方案 »

  1.   

    PHP开发工程师面试试卷1. 请对POSIX风格和兼容Perl风格两种正则表达式的主要函数进行类比说明
    ereg preg_match
    ereg_replace preg_replace
    -------------只用preg,不用ereg
    2. 请说明在php.ini中safe_mode开启之后对于PHP系统函数的影响
    ------------这个可看PHP.ini中注释3. PHP5中魔术方法函数有哪几个,请举例说明各自的用法
    4. 请写出让,并说明如何在命令行下运行PHP脚本(写出两种方式)同时向PHP脚本传递参数?
    一般的为shell方式吧:system excu之类的5. PHP的垃圾收集机制是怎样的
     -----根据概率收集
    6.使对象可以像数组一样进行foreach循环,要求属性必须是私有。
    (Iterator模式的PHP5实现,写一类实现Iterator接口)
      -----可以,对于对象返回,可以用 这种方法读属性
    7.请写一段PHP代码,确保多个进程同时写入同一个文件成功
    ----没写过,要锁定文件吗,要么就appaend写入
    8. 用PHP实现一个双向队列
        -----没听说过什么是双向对列
    9. 使用正则表达式提取一段标识语言(html或xml)代码段中指定标签的指定属性值(需考虑属性值对不规则的情况,如大小写不敏感,属性名值与等号间有空格等)。此处假设需提取test标签的attr属性值,请自行构建包含该标签的串
    ---这个很简单,可以任意提取
    10.请使用socket相关函数(非curl)实现如下功能:构造一个post请求,发送到指定http server的指定端口的指定请求路径(如http://www.example.com:8080/test)。请求中包含以下变量:-----这个考的是http协议和socket通信
    ---试过socket通信GET请求用户名(username):温柔一刀
    密码(pwd):&123=321&321=123&
    个人简介(intro):Hello world!
    ------这个可能要POST请求且该http server需要以下cookie来进行简单的用户动作跟踪:cur_query:you&me
    last_tm:...(上次请求的unix时间戳,定为当前请求时间前10分钟)
    cur_tm:...(当前请求的unix时间戳)设置超时为10秒,发出请求后,将http server的响应内容输出。Function encode($data, $sep = ‘&’){
    while (list($k,$v) = each($data)) {
    $encoded .= ($encoded ? "$sep" : "");
    $encoded .= rawurlencode($k)."=".rawurlencode($v);
    }
    Return $encoded;
    }Function post($url, $post, $cookie){
    $url = parse_url($url);
    $post = encode($data, ‘&’);
    $cookie = encode($cookieArray, ‘;’);
    $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10);
    if (!$fp) return "Failed to open socket to $url[host]";fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));
    fputs($fp, "Host: $url[host]\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
    fputs($fp, "Content-length: " . strlen($encoded) . "\n");
    fputs($fp, "Cookie: $cookie\n\n");
    fputs($fp, "Connection: close\n\n");
    fputs($fp, "$post \n");  while (!feof($fp)) {
          echo fgets($fp, 128);
      }
      fclose($fp);
    }$url = ‘http://www.example.com:8080/test’;
    $encoded = username=温柔一刀& pwd=
    $post = array(
    ‘username’=> ‘温柔一刀’,
    ‘pwd => ‘&123=321&321=123&’,
    ‘intro => ‘Hello world!’
    );
    $cookie = array(
    ‘cur_query’ => ‘you&me,
    ‘last_tm’ => time() - 600,
    ‘cur_tm ‘=> time()
    );Post($url, $post, $cookie);
    11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在?
    ---没做过解,计数或计时吧!SQL会有执行时间
      

  2.   

    11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在? php 不知道,数据库可以插入上百万条数据测试。太难。没得三五年功底基本是白卷
      

  3.   

    1. 请对POSIX风格和兼容Perl风格两种正则表达式的主要函数进行类比说明 
    ereg preg_match 
    ereg_replace preg_replace 
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    preg更快些,别的就不知道了。
    2. 请说明在php.ini中safe_mode开启之后对于PHP系统函数的影响 
    -------------------------------------------------------
    只知道一些涉及安全的函数会不被执行,system,execu。
    3. PHP5中魔术方法函数有哪几个,请举例说明各自的用法 __sleep 
    __wakeup 
    __toString 
    __set_state 
    __construct, 
    __destruct 
    __call, 
    __get, 
    __set, 
    __isset, 
    __unset 
    __sleep, 
    __wakeup, 
    __toString, 
    __set_state, 
    __clone 
    __autoload 
    -----------------------------------
    好多没有用过4. 请写出让,并说明如何在命令行下运行PHP脚本(写出两种方式)同时向PHP脚本传递参数? 
    --------------------------
    php.exe test.php 1 2 3,不知道另一种方式。5. PHP的垃圾收集机制是怎样的 
    -------------------------
    不知道6.使对象可以像数组一样进行foreach循环,要求属性必须是私有。 
    (Iterator模式的PHP5实现,写一类实现Iterator接口)
    ------------------------- 
    不明白7.请写一段PHP代码,确保多个进程同时写入同一个文件成功 
    -------------------------
    建立一个标记文件,采用独占写入。8. 用PHP实现一个双向队列 
    -------------------------
    两个指针一个数据体的数组结构么?
    9. 使用正则表达式提取一段标识语言(html或xml)代码段中指定标签的指定属性值(需考虑属性值对不规则的情况,如大小写不敏感,属性名值与等号间有空格等)。此处假设需提取test标签的attr属性值,请自行构建包含该标签的串 <test attr=”ddd”> <test attr\s*=\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_query:you&me 
    last_tm:...(上次请求的unix时间戳,定为当前请求时间前10分钟) 
    cur_tm:...(当前请求的unix时间戳) 设置超时为10秒,发出请求后,将http server的响应内容输出。 Function encode($data, $sep = ‘&’){ 
    while (list($k,$v) = each($data)) { 
    $encoded .= ($encoded ? "$sep" : ""); 
    $encoded .= rawurlencode($k)."=".rawurlencode($v); 

    Return $encoded; 
    } Function post($url, $post, $cookie){ 
    $url = parse_url($url); 
    $post = encode($data, ‘&’); 
    $cookie = encode($cookieArray, ‘;’); 
    $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10); 
    if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query'])); 
    fputs($fp, "Host: $url[host]\n"); 
    fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); 
    fputs($fp, "Content-length: " . strlen($encoded) . "\n"); 
    fputs($fp, "Cookie: $cookie\n\n"); 
    fputs($fp, "Connection: close\n\n"); 
    fputs($fp, "$post \n");   while (!feof($fp)) { 
          echo fgets($fp, 128); 
      } 
      fclose($fp); 
    } $url = ‘http://www.example.com:8080/test’; 
    $encoded = username=温柔一刀& pwd= 
    $post = array( 
    ‘username’=> ‘温柔一刀’, 
    ‘pwd => ‘&123=321&321=123&’, 
    ‘intro => ‘Hello world!’ 
    ); 
    $cookie = array( 
    ‘cur_query’ => ‘you&me, 
    ‘last_tm’ => time() - 600, 
    ‘cur_tm ‘=> time() 
    ); Post($url, $post, $cookie); 
    -------------------------------
    新帆的温柔一刀什么时候去了腾讯?11.你用什么方法检查PHP脚本的执行效率(通常是脚本执行时间)和数据库SQL的效率(通常是数据库Query时间),并定位和分析脚本执行和数据库查询的瓶颈所在? 
    1.脚本执行时间,启用xdebug,使用WinCacheGrind分析。 
    2.数据库查询,mysql使用EXPLAIN分析查询,启用slow query log记录慢查询。 
    ------------------------------------------------------------
    前后加time(),数据库直接在consle执行。
      

  4.   

    首先申明上面的题目我完成不了几个,楼上说得有道理,有必要对什么都那么清楚么,在PHP领域,能解决问题的
    方法就是好方法. 就拿那个正则来说,懂得用ereg的估计也没有几个,再说有必要明白那个么?我可能也只会用那
    个做一些是否包含的判断而已.
      

  5.   

    1 不熟悉2 安全模式下exec system 只能执行指定目录下的SHELL命名3 __construct 构造函数 被实例化时调用
      __call() 未知方法时被调用 传入方法名和值
      __set() 给未知属性赋时调用 传入属性名和值
      __get()获得未知属性时调用 同上
      __destruct 析构函数 被销毁时调用
      其他只在手册中见过 没用过 4 /usr/bin/php /usr/local/apache/test.php
      /usr/local/apache/test.php
      test.php首行为#!/usr/bin/php -qd
      参数在$argv数组中5 不知道 只知道在脚本运行完自动释放资源 session按照几率回收过期数据6 不明白什么意思 历边实例化的类中的所有属性?7 可以在成功打开文件后做标记 将文件时间设置为未来时间 权限 所有者 方式做随机数值标记 完成后改为正常8 不明白题目的意思 如果就列队来说可以用数组实现 9 用正则取得标签 历边字符串分析标签10 按照HTTP 1.1的格式发送字符串就可以 正则获取COOKIE并在下次提交时发送11 XDEBUG分析PHP运行时间 各平台都有GUI工具很直观
       MYSQL性能分析 有日志可用 且有GUI工具做图形化分析
      

  6.   

    迭代器的东西估计看过STL的人都应该不会觉得很难吧,还有双向队列也是,直接用数组就可以实现了。php数组的索引可以是复数的。
      

  7.   

    很好的一套试题的说,正是应对了现在我们国内php程序员的通病,掌握知识不扎实。
    其实这套题数目不多,方位广泛,能考察面试者以前从事工作的广度和深度。
    个人认为,一套试题要实现它的考察任务,不是为了让大家答满分儿的。
    如果腾讯再有一份对国内大部分程序员对这套试题的得分范围,
    以此来筛选适合自己的php程序员,简直绝了。
      

  8.   

    6.使对象可以像数组一样进行foreach循环,要求属性必须是私有。  
    (Iterator模式的PHP5实现,写一类实现Iterator接口)class myclass implements Iterator{public function __construct($start,$end){
    $this->start=$start;
        $this->end=$end;
        }public function rewind(){
    $this->cur=$this->start;
        }public function key(){
    return $this->cur;
        }public function current(){
    return pow($this->cur,2);
        }public function next(){
    $this->cur++;
        }public function valid(){
    return $this->cur<=$this->end;
        }private $start,$end;
    private $cur;
    }$obj=new myclass(3,6);
    foreach($obj as $key=>$value){       printf('%s,%s<br/>',$key,$value);
        }