lbk60ox 发表于 2024-10-4 12:50:59

2020年BAT大厂PHP工程师面试题整理(附带答案)


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/LFP9SpGv0PGkbfEiaOdXZGibL9ZRz5dEfFBck3dm4Qjyme95ryc8jTAtB3DXeLXdR7h4sB44yoIo87RoCCKZEQxQ/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">今天下午来到北京百度科技园进行面试PHP工程师岗位。面试官问了<span style="color: black;">非常多</span>问题,</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">由于</span><span style="color: black;">重点</span>是从事php方面的,<span style="color: black;">因此</span>下面谈的这些面试问题<span style="color: black;">重点</span>都是php方面的,</strong></span><span style="color: black;">当然其它的语言面试有些问题<span style="color: black;">亦</span>会被问到。我大概整理回忆下:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP<span style="color: black;">研发</span>工程师笔试试卷</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">姓名:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">1、</span>PHP<span style="color: black;">研发</span>部分</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1.合并两个数组有几种方式,试比较它们的异同</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:&nbsp;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)array_merge()</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)’+’</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)array_merge_recursive</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">array_merge 简单的合并数组</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">array_merge_recursive 合并两个数组,<span style="color: black;">倘若</span>数组中有完全<span style="color: black;">同样</span>的数据,将它们递归合并</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">array_combine 和 ‘+’ :合并两个数组,前者的值<span style="color: black;">做为</span>新数组的键</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2.请写一个函数来<span style="color: black;">检测</span>用户提交的数据<span style="color: black;">是不是</span>为整数</span></strong></span><span style="color: black;">(不区分数据类型,<span style="color: black;">能够</span>为二进制、八进制、十进制、十六进制数字)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">其实<span style="color: black;">重点</span>还是is_int和 floor 这个<span style="color: black;">办法</span></span></p><span style="color: black;">if(!is_numeric($jp_total)||strpos($jp_total,".")!==false){</span><span style="color: black;">echo "不是整数";</span><span style="color: black;">}else{</span><span style="color: black;"> echo "是整数";</span><span style="color: black;">}</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3.PHP的strtolower()和strtoupper()函数</span></strong></span><span style="color: black;">在安装非中文系统的服务器下可能会<span style="color: black;">引起</span>将汉字转换为乱码,请写两个替代的函数实现兼容Unicode文字的字符串<span style="color: black;">体积</span>写转换</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">原由</span>是:</strong>中文<span style="color: black;">是由于</span>多字节<span style="color: black;">构成</span>的,而<span style="color: black;">仅有</span>英文系统的单个英文字符<span style="color: black;">仅有</span>一个字节,<span style="color: black;">因此</span>该系统把中文的每一个字节都做了strtolower()处理,改变后的中文字节拼接在<span style="color: black;">一块</span>就<span style="color: black;">成为了</span>乱码(新生成的编码映射对应的字符可能就不是中文了)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">手动<span style="color: black;">处理</span>:</span></strong><span style="color: black;">用str_split(string string,intstring,intsplit_length = 1)按<span style="color: black;">每一个</span>字节切割,像中文能切割成三个字节。对识别到的字节若是英文字母则进行转换。</span></p><span style="color: black;">&lt;?php</span><span style="color: black;">function mystrtoupper($a){</span><span style="color: black;"> $b = str_split($a, 1);</span><span style="color: black;"> $r = ;</span><span style="color: black;"> foreach($b as $v){</span><span style="color: black;"> $v = ord($v);</span><span style="color: black;"> if($v &gt;= 97 &amp;&amp; $v&lt;= 122){</span><span style="color: black;"> $v -= 32;</span><span style="color: black;"> }</span><span style="color: black;">$r .= chr($v);</span><span style="color: black;"> }</span><span style="color: black;"> return $r;</span><span style="color: black;">}</span><span style="color: black;">$a = a中你继续F@#$%^&amp;*(BMDJFDoalsdkfjasl;</span><span style="color: black;">echo origin string:.$a."\n";</span><span style="color: black;">echo result string:;</span><span style="color: black;">$r = mystrtoupper($a);</span><span style="color: black;">var_dump($r);</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4.PHP的is_writeable()函数存在Bug,</span></strong></span><span style="color: black;"><span style="color: black;">没法</span>准确判断一个目录/文件<span style="color: black;">是不是</span>可写,请写一个函数来判断目录/文件<span style="color: black;">是不是</span>绝对可写</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">其中bug存在两个方面,</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)在windowns中,当文件<span style="color: black;">仅有</span>只读属性时,is_writeable()函数才返回false,当返回true时,该文件不<span style="color: black;">必定</span>是可写的。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>是目录,在目录中新建文件并<span style="color: black;">经过</span>打开文件来判断;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>是文件,<span style="color: black;">能够</span><span style="color: black;">经过</span>打开文件(fopen),来测试文件<span style="color: black;">是不是</span>可写。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)在Unix中,当php配置文件中开启safe_mode时(safe_mode=on),is_writeable()<span style="color: black;">一样</span>不可用。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">读取配置文件<span style="color: black;">是不是</span>safe_mode<span style="color: black;">是不是</span>开启。</span></p><span style="color: black;">/**</span><span style="color: black;">* Tests for file writability</span><span style="color: black;">*</span><span style="color: black;">* is_writable() returns TRUE on Windows servers when you really cant write to</span><span style="color: black;">* the file, based on the read-only attribute. is_writable() is also unreliable</span><span style="color: black;">* on Unix servers if safe_mode is on.</span><span style="color: black;">*</span><span style="color: black;">* @access private</span><span style="color: black;">* @return void</span><span style="color: black;">*/</span><span style="color: black;">if ( ! function_exists(is_really_writable))</span><span style="color: black;">{</span><span style="color: black;">function is_really_writable($file)</span><span style="color: black;">{</span><span style="color: black;"> // If were on a Unix server with safe_mode off we call is_writable</span><span style="color: black;">if (DIRECTORY_SEPARATOR == / AND @ini_get("safe_mode") == FALSE)</span><span style="color: black;"> {</span><span style="color: black;"> return is_writable($file);</span><span style="color: black;"> }</span><span style="color: black;"> // For windows servers and safe_mode "on" installations well actually</span><span style="color: black;"> // write a file then read it. Bah...</span><span style="color: black;">if (is_dir($file))</span><span style="color: black;"> {</span><span style="color: black;"> $file = rtrim($file, /)./.md5(mt_rand(1,100).mt_rand(1,100));</span><span style="color: black;"> if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)</span><span style="color: black;"> {</span><span style="color: black;"> return FALSE;</span><span style="color: black;"> }</span><span style="color: black;"> fclose($fp);</span><span style="color: black;">@chmod($file, DIR_WRITE_MODE);</span><span style="color: black;"> @unlink($file);</span><span style="color: black;"> return TRUE;</span><span style="color: black;"> } elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) {</span><span style="color: black;">return FALSE;</span><span style="color: black;"> }</span><span style="color: black;"> fclose($fp);</span><span style="color: black;"> return TRUE;</span><span style="color: black;"> }</span><span style="color: black;">}</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">5.</span></strong><strong style="color: blue;"><span style="color: black;">PHP处理上传文件信息数组中的文件类型</span></strong></span><span style="color: black;">$_FILES[‘type’]由客户端浏览器<span style="color: black;">供给</span>,有可能是黑客伪造的信息,请写一个函数来<span style="color: black;">保证</span>用户上传的图像文件类型真实<span style="color: black;">靠谱</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">用getimagesize来判断上传<span style="color: black;">照片</span>的类型比$_FILES函数的type更<span style="color: black;">靠谱</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">同一个文件,<span style="color: black;">运用</span><span style="color: black;">区别</span>的浏览器php返回的type类型是不<span style="color: black;">同样</span>的,由浏览器<span style="color: black;">供给</span>type类型的话,就有可能被黑客利用向服务器提交一个伪装撑<span style="color: black;">照片</span>后缀的可执行文件。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">能够</span><span style="color: black;">经过</span>getimagesize()函数来判断上传的文件类型,<span style="color: black;">倘若</span>是头像文件 会返回<span style="color: black;">这般</span>的一个数组</span></p><span style="color: black;">Array(</span><span style="color: black;"> =&gt; 331</span><span style="color: black;"> =&gt; 234</span><span style="color: black;"> =&gt; 3</span><span style="color: black;"> =&gt; width="331" height="234"</span><span style="color: black;"> =&gt; 8</span><span style="color: black;"> =&gt; image/png</span><span style="color: black;">);</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span><span style="color: black;">经过</span>getimagesize()函数返回的是<span style="color: black;">这般</span>的一个数组 说明上传的是头像文件。其中索引为2的<span style="color: black;">暗示</span>类型</span></p><span style="color: black;">1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte</span><span style="color: black;">order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 =</span><span style="color: black;">JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM,</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">你<span style="color: black;">能够</span><span style="color: black;">经过</span>这个再去限制上传的头像类型</span></p><span style="color: black;">&lt;?php</span><span style="color: black;"> $file=$_FILES;</span><span style="color: black;"> if(!empty($file))</span><span style="color: black;"> {</span><span style="color: black;"> var_dump($file);</span><span style="color: black;"> var_dump(getimagesize($file["tmp_name"]));</span><span style="color: black;"> } </span><span style="color: black;">?&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6.PHP<span style="color: black;">经过</span>对数据的URL编码来实现与Javascript的数据交互,</span></strong></span><span style="color: black;"><span style="color: black;">然则</span><span style="color: black;">针对</span>部分特殊字符的编解码与Javascript的规则不尽相同,请<span style="color: black;">详细</span>说明这种差异,并针对UTF-8字符集的数据,写出PHP的编解码函数和Javascript的编解码函数,<span style="color: black;">保证</span>PHP编码数据<span style="color: black;">能够</span>被Javascript正确解码 、Javascript编码的数据<span style="color: black;">能够</span>被PHP正确解码</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p><span style="color: black;">&lt;?php</span><span style="color: black;"> $str = 思源博客siyuantlw/tlw/sy/俺只是一个打酱油的;</span><span style="color: black;"> $str = iconv("GB2312",UTF-8,$str);</span><span style="color: black;"> $str = urlencode($str);</span><span style="color: black;">?&gt;</span><span style="color: black;">//js decodeURIComponent 貌似对GB2312编码的格式不识别,必须转为utf-8才<span style="color: black;">能够</span>,<span style="color: black;">而后</span>,<span style="color: black;">倘若</span>字符串中有空格的 就转为 + 号了</span><span style="color: black;">&lt;html&gt;</span><span style="color: black;"> &lt;script&gt;</span><span style="color: black;"> var ds = &lt;?php echo $str;?&gt;;</span><span style="color: black;"> var dddd= decodeURIComponent (ds);</span><span style="color: black;"> alert(dddd);</span><span style="color: black;">&lt;/script&gt;</span><span style="color: black;">&lt;/html&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">7.试阐述Memcache的key多节点分布的算法?</span></strong></span><span style="color: black;">当任一节点<span style="color: black;">显现</span>故障时PHP的Memcache客户端将<span style="color: black;">怎样</span>处置?<span style="color: black;">怎样</span><span style="color: black;">保证</span>Memcache数据读写操作的原子性?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">原理:一致性hash&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">原子性</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">原子性会<span style="color: black;">引起</span>的问题:简单的说<span style="color: black;">便是</span>A,B<span style="color: black;">皆想</span>操作key1,<span style="color: black;">而后</span>都在key1上<span style="color: black;">增多</span>自己的信息,就会有问题</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">memcached是原子的吗?</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">宏观</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">所有的被发送到memcached的单个命令是完全原子的。<span style="color: black;">倘若</span>您针对同一份数据<span style="color: black;">同期</span>发送了一个set命令和一个get命令,它们不会影响对方。它们将被串行化、先后执行。即使在多线程模式,所有的命令都是原子的;命令序列不是原子的。<span style="color: black;">倘若</span>您<span style="color: black;">经过</span>get命令获取了一个item,修改了它,<span style="color: black;">而后</span>想把它set回memcached,<span style="color: black;">咱们</span>不<span style="color: black;">保准</span>这个item<span style="color: black;">无</span>被其他进程(process,未必是操作系统中的进程)操作过。在并发的<span style="color: black;">状况</span>下,您<span style="color: black;">亦</span>可能覆写了一个被其他进程set的item。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">memcached 1.2.5以及更高版本,<span style="color: black;">供给</span>了gets和cas命令,它们<span style="color: black;">能够</span><span style="color: black;">处理</span>上面的问题。<span style="color: black;">倘若</span>您<span style="color: black;">运用</span>gets命令<span style="color: black;">查找</span>某个key的item,memcached会 给您返回该item当前值的<span style="color: black;">独一</span>标识。<span style="color: black;">倘若</span>您覆写了这个item并想把它写回到memcached中,您<span style="color: black;">能够</span><span style="color: black;">经过</span>cas命令把那个<span style="color: black;">独一</span>标识<span style="color: black;">一块</span>发送给 memcached。<span style="color: black;">倘若</span>该item存放在memcached中的<span style="color: black;">独一</span>标识与您<span style="color: black;">供给</span>的一致,您的写操作将会成功。<span style="color: black;">倘若</span>另一个进程在这<span style="color: black;">时期</span><span style="color: black;">亦</span>修改了这个 item,<span style="color: black;">那样</span>该item存放在memcached中的<span style="color: black;">独一</span>标识将会改变,您的写操作就会失败。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">8.<span style="color: black;">怎样</span>实现PHP的安全最大化?<span style="color: black;">怎么样</span>避免SQL注入漏洞和XSS跨站脚本攻击漏洞?</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基本原则:不对外界展示服务器或程序设计细节(屏蔽错误),不相信任何用户提交的数据(过滤用户提交)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)屏蔽错误,将display_errors 设置为off</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)过滤用户提交参数,<span style="color: black;">这儿</span>需要<span style="color: black;">重视</span>的是<span style="color: black;">不可</span>仅仅<span style="color: black;">经过</span>浏览器端的验证,还需要经过服务器端的过滤</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这儿</span>是需要<span style="color: black;">重视</span>最多的<span style="color: black;">地区</span>,<span style="color: black;">由于</span>所有用户提交的数据入口都在<span style="color: black;">这儿</span>,这是过滤数据的<span style="color: black;">第1</span>步。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">思虑</span><span style="color: black;">是不是</span>过滤select,insert,update,delete,drop,create等直接操作数据的命令语句</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>addslashes 将所有特殊字符过滤</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">打开magic_quotes_gpc,开启该参数数后自动将sql语句转换,将 转换成 &nbsp;\</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)<span style="color: black;">能够</span><span style="color: black;">思虑</span>设置统一入口,只<span style="color: black;">准许</span>用户<span style="color: black;">经过</span>指定的入口<span style="color: black;">拜访</span>,<span style="color: black;">不可</span><span style="color: black;">拜访</span>未经许可的文件等内容</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4)<span style="color: black;">能够</span><span style="color: black;">思虑</span>对安全性<span style="color: black;">需求</span>高的文件进行<span style="color: black;">源自</span>验证,<span style="color: black;">例如</span><span style="color: black;">想要</span>执行b.php必须先执行a.php,<span style="color: black;">能够</span>在b.php中判断来自a.php的referer,避免用户直接执行b.php</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">2、</span>系统<span style="color: black;">关联</span>部分</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1.请简述Linux/BSD系统下进程间通讯的方式有<span style="color: black;">那些</span>,并<span style="color: black;">详细</span>说明在PHP下<span style="color: black;">怎样</span>实现</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">管道(Pipe)及有名管道(namedpipe):管道可用于<span style="color: black;">拥有</span>亲缘关系进程间的通信,有名管道克服了管道<span style="color: black;">无</span>名字的限制,<span style="color: black;">因此呢</span>,除<span style="color: black;">拥有</span>管道所<span style="color: black;">拥有</span>的功能外,它还<span style="color: black;">准许</span>无亲缘关系进程间的通信;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">信号(Signal):信号是比较<span style="color: black;">繁杂</span>的通信方式,用于<span style="color: black;">通告</span>接受进程有某种事件<span style="color: black;">出现</span>,除了用于进程间通信外,进程还<span style="color: black;">能够</span>发送信号给进程本身;linux除了支持Unix<span style="color: black;">初期</span>信号语义函数sigal外,还支持语义符合Posix.1标准的信号函数sigaction(<span style="color: black;">实质</span>上,该函数是基于BSD的,BSD为了实现<span style="color: black;">靠谱</span>信号机制,又能够统一对外接口,用sigaction函数重新实现了signal函数);</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">报文(Message)队列(<span style="color: black;">信息</span>队列):<span style="color: black;">信息</span>队列是<span style="color: black;">信息</span>的链接表,<span style="color: black;">包含</span>Posix<span style="color: black;">信息</span>队列systemV<span style="color: black;">信息</span>队列。有足够权限的进程<span style="color: black;">能够</span>向队列中添加<span style="color: black;">信息</span>,被赋予读权限的进程则<span style="color: black;">能够</span>读走队列中的<span style="color: black;">信息</span>。<span style="color: black;">信息</span>队列克服了信号承载信息量少,管道只能承载无格式字节流以及缓冲区<span style="color: black;">体积</span>受限等缺点。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">共享内存:使得多个进程<span style="color: black;">能够</span><span style="color: black;">拜访</span>同<span style="color: black;">一起</span>内存空间,是最快的可用IPC形式。是针对其他通信机制运行效率较低而设计的。<span style="color: black;">常常</span>与其它通信机制,如信号量结合<span style="color: black;">运用</span>,来达到进程间的同步及互斥。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">信号量(semaphore):<span style="color: black;">重点</span><span style="color: black;">做为</span>进程间以及同一进程<span style="color: black;">区别</span>线程之间的同步手段。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">套接口(Socket):更为<span style="color: black;">通常</span>的进程间通信机制,可用于<span style="color: black;">区别</span><span style="color: black;">设备</span>之间的进程间通信。起初<span style="color: black;">是由于</span>Unix系统的BSD分支<span style="color: black;">研发</span>出来的,但<span style="color: black;">此刻</span><span style="color: black;">通常</span><span style="color: black;">能够</span>移植到其它类Unix系统上:Linux和SystemV的变种都支持套接字。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2.<span style="color: black;">为何</span>会<span style="color: black;">显现</span>僵死进程(孤儿进程)?<span style="color: black;">怎么样</span>查看僵死进程?<span style="color: black;">怎样</span><span style="color: black;">处理</span>僵死进程问题?</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">僵尸进程:</span></strong><span style="color: black;">一个进程<span style="color: black;">运用</span>fork创建子进程,<span style="color: black;">倘若</span>子进程退出,而父进程并<span style="color: black;">无</span>调用wait或waitpid获取子进程的状态信息,<span style="color: black;">那样</span>子进程的进程描述符仍然<span style="color: black;">保留</span>在系统中。这种进程<span style="color: black;">叫作</span>之为僵死进程。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">查看:</span></strong><span style="color: black;"><span style="color: black;">运用</span>ps aux</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">删除:</span></strong><span style="color: black;">ps aux | grep -e ‘^ ’ | awk ‘{print $2}’ | xargs kill -9</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3.请描述Apache 2.x版本的MPM(Multi-Processing Module)机制,并<span style="color: black;">详细</span>说明在<span style="color: black;">区别</span>的MPM机制下<span style="color: black;">怎样</span>支持PHP?</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">常用的应该就<span style="color: black;">仅有</span>3个:worker、prefork、perchild</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">prefork:</span></strong><span style="color: black;">在功能上<span style="color: black;">便是</span><span style="color: black;">运用</span>Apache的运行方式,一个父进程,<span style="color: black;">而后</span><span style="color: black;">按照</span>设置以及连接<span style="color: black;">状况</span>生成相应的子进程数。这种模式<span style="color: black;">靠谱</span>性和健壮性都是最好的。<span style="color: black;">然则</span>在性能上,开销过大。达不到<span style="color: black;">咱们</span>这些“吸血鬼”的<span style="color: black;">需求</span>了_。<span style="color: black;">倘若</span>连接数<span style="color: black;">太多</span>的话,会<span style="color: black;">引起</span><span style="color: black;">咱们</span><span style="color: black;">没法</span>远程登陆,<span style="color: black;">必定</span>要等到连接数下降后<span style="color: black;">才可</span>连接,这<span style="color: black;">亦</span>是最让我头痛的事情。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">worker:</span></strong><span style="color: black;">混合线程/进程的MPM。一个父进程,后面是带有线程的子进程。<span style="color: black;">每一个</span>子进程的线程数是固定且相同的。这是最“平庸”的一个模式,但<span style="color: black;">亦</span>是<span style="color: black;">运用</span>人最多的一种模式。<span style="color: black;">由于</span>它性能等各方面比较<span style="color: black;">平衡</span>。性能上要比prefork好<span style="color: black;">有些</span>,只是牺牲了一点点的健壮性和<span style="color: black;">靠谱</span>性<span style="color: black;">罢了</span>。<span style="color: black;">通常</span><span style="color: black;">举荐</span><span style="color: black;">运用</span>这个选项。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">perchild:</span></strong><span style="color: black;"><span style="color: black;">亦</span>是混合线程/进程的MPM。当<span style="color: black;">起步</span>perchild MPM时,它会<span style="color: black;">创立</span>指定数量的子进程,且<span style="color: black;">每一个</span>子进程都<span style="color: black;">拥有</span>指定数量的线程,如负载<span style="color: black;">增多</span>了,那它不会<span style="color: black;">创立</span>新的进程(子进程是固定的),只是在子进程下<span style="color: black;">创立</span>新的线程。它还有一个特点<span style="color: black;">便是</span><span style="color: black;">能够</span>为每一个子进程配置<span style="color: black;">区别</span>的用户和组。<span style="color: black;">亦</span><span style="color: black;">能够</span>为<span style="color: black;">每一个</span>虚拟主机指定一个子进程。这种模式性能是最佳的,<span style="color: black;">然则</span><span style="color: black;">靠谱</span>性和健壮性就相对是最差的。各取所需,我个人觉得这种模式<span style="color: black;">亦</span>不错,<span style="color: black;">倘若</span>你<span style="color: black;">不消</span>第三方的模块的话_。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4.请简述PHP在Apache下的几种运行方式并加以比较?<span style="color: black;">怎样</span>让PHP在Linux+Apache下以Fast CGI方式运行?</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">php在apache有3中运行方式:CGI模式、FastCGI模式、Apache 模块DLL。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">比较:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">Cgi模式和模块dll加载方式比较:</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Cgi模式下,apache调用<span style="color: black;">外边</span>执行器php.exe执行php代码,并将解释后生成的html代码和原html整合,再传递给apache服务器,其在执行时每次都需要重新解析php.ini、重新载入<span style="color: black;">所有</span>dll扩展并重初始化<span style="color: black;">所有</span>数据结构,运行速度非常慢,但<span style="color: black;">由于</span>是<span style="color: black;">外边</span>加载执行器,php代码执行出错不会<span style="color: black;">引起</span>apache崩溃。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在模块化(DLL)中,PHP是与Web服务器<span style="color: black;">一块</span><span style="color: black;">起步</span>并运行的。<span style="color: black;">因此</span>从某种<span style="color: black;">方向</span>上<span style="color: black;">来讲</span>,以apache模块方式安装的 PHP4有着比CGI模式更好的安全性以及更好的执行效率和速度。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">Cgi和fastcgi模式比较:</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Fastcig是cgi的升级版,Cgi和fastcgi工作模式大抵相同,但fastcgi模式中fastcgi的进程管理器可用来管理cgi解释器,该管理器在cgi解释器完成请求后,会<span style="color: black;">处在</span>挂起状态,用以等待接下来的请求,<span style="color: black;">由于</span>向比较cgi每次都需要重新解析php.ini、重新载入<span style="color: black;">所有</span>dll扩展并重初始化<span style="color: black;">所有</span>数据结构,fastcig模式<span style="color: black;">显著</span>要快<span style="color: black;">非常多</span>。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">5.请写出让PHP能够</span></strong></span><span style="color: black;">在命令行下以脚本方式执行时安装PHP所必须指定的configure参数,并说明<span style="color: black;">怎样</span>在命令行下运行PHP脚本(写出两种方式)<span style="color: black;">同期</span>向PHP脚本传递参数?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">因为</span> –enable-cli 和 –enable-cgi <span style="color: black;">同期</span>默认有效,<span style="color: black;">因此呢</span>,不必再配置行中加上 –enable-cli 来使得 CLI 在 make install 过程中被拷贝到 {PREFIX}/bin/php</span></p><span style="color: black;">php -f “index.php”</span><span style="color: black;">php -r “print_r(get_defined_constants());”</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">试题二:</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1、请列举你能想到的UNIX信号,并说明信号用途。</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Unix信号量<span style="color: black;">亦</span><span style="color: black;">能够</span>在文件/usr/include/sys/signal.h中查看</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SIGHUP 进程由於<span style="color: black;">掌控</span>终端死去<span style="color: black;">或</span><span style="color: black;">掌控</span>终端发出起命令</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SIGINT 键盘中断所产生的信号</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SIGQUIT 键盘终止</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2、请列举、你能想到的所有的字符串<span style="color: black;">查询</span>算法,并加注释简单说明。</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">次序</span><span style="color: black;">查询</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">二分<span style="color: black;">查询</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分块<span style="color: black;">查询</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">哈希表<span style="color: black;">查询</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3、有一个IP<span style="color: black;">位置</span>(192.168.0.1),请写出其32位无符号整数形式。</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">此题是将十进制转换成二进制 采用取余法<span style="color: black;">就可</span>很简单 答案是:11000000.10101000.00000000.00000001 千万<span style="color: black;">不可</span>只记答案哦</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4、写出、你能想到的所有HTTP返回状态值,并说明用途</span></strong></span><span style="color: black;">(<span style="color: black;">例如</span>:返回404<span style="color: black;">暗示</span>找不到页面)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">200 (成功) 服务器已成功处理了请求。<span style="color: black;">一般</span>,这<span style="color: black;">暗示</span>服务器<span style="color: black;">供给</span>了请求的网页。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">301 (永久移动) 请求的网页已永久移动到新位置。服务器返回此响应(对 GET 或 HEAD 请求的响应)时,会自动将请求者转到新位置。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">302 (临时移动) 服务器<span style="color: black;">日前</span>从<span style="color: black;">区别</span>位置的网页响应请求,但请求者应继续<span style="color: black;">运用</span>原有位置来进行以后的请求。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">401 (未授权) 请求<span style="color: black;">需求</span>身份验证。<span style="color: black;">针对</span>需要登录的网页,服务器可能返回此响应。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">403 (禁止) 服务器拒绝请求。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">404 (未找到) 服务器找不到请求的网页。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">500 (服务器内部错误) 服务器遇到错误,<span style="color: black;">没法</span>完成请求。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">501 (尚未实施) 服务器不具备完成请求的功能。例如,服务器<span style="color: black;">没法</span>识别请求<span style="color: black;">办法</span>时可能会返回此代码。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">502 (错误网关) 服务器<span style="color: black;">做为</span>网关或代理,从上游服务器收到无效响应。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">503 (服务不可用) 服务器<span style="color: black;">日前</span><span style="color: black;">没法</span><span style="color: black;">运用</span>(<span style="color: black;">因为</span>超载或停机<span style="color: black;">守护</span>)。<span style="color: black;">一般</span>,这只是暂时状态。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">504 (网关超时) 服务器<span style="color: black;">做为</span>网关或代理,<span style="color: black;">然则</span><span style="color: black;">无</span><span style="color: black;">即时</span>从上游服务器收到请求。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">505 (HTTP 版本不受支持) 服务器不支持请求中所用的 HTTP 协议版本。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">基本</span>任务-选作(会得到额外分数):</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">画几个你最<span style="color: black;">熟练</span>的SERVER端模型出来(格式不重要,<span style="color: black;">尽可能</span>将图画清楚,说明思路<span style="color: black;">就可</span>)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">进阶任务:</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1、PHP的垃圾收集机制是<span style="color: black;">怎么样</span>的?</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">说明:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)<span style="color: black;">倘若</span>,你<span style="color: black;">熟练</span>PHP源码,<span style="color: black;">那样</span>请从源码入手,回答些问题,会<span style="color: black;">得到</span>额外加分</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)<span style="color: black;">倘若</span>,你不<span style="color: black;">熟练</span>PHP源码,<span style="color: black;">那样</span>尽你所能,多写点东西,<span style="color: black;">包含</span>利用自己的编程直觉得到的信息,都<span style="color: black;">能够</span>。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)对,则有分,错误不扣,不写无分。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:PHP<span style="color: black;">能够</span>自动进行内存管理,清除<span style="color: black;">再也不</span>需要的对象。PHP<span style="color: black;">运用</span>了引用计数(referencecounting)这种单纯的垃圾回收(garbagecollection)机制。<span style="color: black;">每一个</span>对象都内含一个引用计数器,<span style="color: black;">每一个</span>reference连接到对象,计数器加1。当reference离开<span style="color: black;">存活</span>空间或被设为NULL,计数器减1。当某个对象的引用计数器为零时,PHP<span style="color: black;">晓得</span>你将<span style="color: black;">再也不</span>需要<span style="color: black;">运用</span>这个对象,释放其所占的内存空间。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2、请写出HTTP头,并符合以下<span style="color: black;">需求</span>:</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)这是一个post请求</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)<span style="color: black;">目的</span>:http://www.example.com:8080/test</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)POST变量:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">username: test</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">pwd: test2</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">intro: Hello world!</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4)<span style="color: black;">包括</span>以下COOKIE信息:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">cur_query: you&amp;me</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">说明:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)<span style="color: black;">倘若</span>,你记不得某个HTTP协议中的指令字了,<span style="color: black;">那样</span>,无奈这举是用“汉字”代替。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)<span style="color: black;">倘若</span>,你能记住<span style="color: black;">更加多</span>的HTTP协议指令字,<span style="color: black;">那样</span>多写几句,总是没坏处,对吧?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)最关键的,只需要画出正确的“轮廓”(还记得httpwatch等工具打印出来的头部吗?那<span style="color: black;">便是</span>“轮廓”的含义),<span style="color: black;">亦</span>会有分数,但<span style="color: black;">倘若</span>,连“轮廓”都写错了,<span style="color: black;">那样</span>就很遗憾了。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p><span style="color: black;">Accept: text/html <span style="color: black;">能够</span>接受的数据类型</span><span style="color: black;">Accept-Encoding: gzip 接受的压缩类型</span><span style="color: black;">Accept-Language: zh-CN 接受语言</span><span style="color: black;">Cache-Control: no-cache <span style="color: black;">是不是</span>有缓存</span><span style="color: black;">Connection : keep-alive <span style="color: black;">是不是</span>保持链接</span><span style="color: black;">Host:http://www.example.com:8080/test</span><span style="color: black;">Cookie:intro=Hello world!</span><span style="color: black;">Content-Disposition: form-data; username=”test”&amp;pwd=”test2”&amp;intro=”hello world!”</span><span style="color: black;">User-Agent: 浏览器信息</span><span style="color: black;">Referer: 前一个页面<span style="color: black;">位置</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">编程任务:</span></strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span>碰到了大麻烦,一个新来的传教士惹恼了上帝,上帝很愤怒,<span style="color: black;">需求</span><span style="color: black;">咱们</span>把圣经(bbe.txt)背熟,直至他说哪个单词,<span style="color: black;">咱们</span>就要飞快的回答出这个单词在第几行第几个单词位置。听说你是个优秀的程序员,那么<span style="color: black;">帮忙</span><span style="color: black;">咱们</span>完成这个不可能的任务吧。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">需求</span>如下:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)/myworks/example/bbe.txt,98版本英文圣经一本</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)输入部分<span style="color: black;">需求</span>如下:php ./example.php [单词]</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)输出部分如下:[单词] 1,2 2,4 5,6 <span style="color: black;">暗示</span>:此单词在1行2列(第二个单词),2行4列…</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">说明:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)此文本4MB之巨…</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)单词的含义:由英文字母(<span style="color: black;">体积</span>写),数字(0-9)<span style="color: black;">构成</span>的串</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)<span style="color: black;">供给</span>给你的<span style="color: black;">设备</span>OS为ubuntu 9.10,内存<span style="color: black;">仅有</span>1G,<span style="color: black;">况且</span>,很不幸的,其中700M用来做了别的</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4)上机考试不<span style="color: black;">准许</span>上网,但我装了man文档以及读取CHM以及PDF的阅读器,在电脑的桌面的CHM文件夹中,有相应的PHP参考手册</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">5)算法<span style="color: black;">繁杂</span>度<span style="color: black;">需求</span><span style="color: black;">不可</span>大于O(N^2)(<span style="color: black;">便是</span>N的平方)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">6)什么?PHP低效且用起来不顺手,好的,你<span style="color: black;">能够</span>用别的语言来实现。但<span style="color: black;">重视</span>:<span style="color: black;">供给</span>给你的<span style="color: black;">设备</span>上<span style="color: black;">仅有</span>python 2.4/perl 5.8/gcc 4.1</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">答:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">两份答案感觉还<span style="color: black;">能够</span></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">&nbsp;bbe.txt文件咱们<span style="color: black;">无</span> 想像成是 空格 隔开的算了</span></p><span style="color: black;">hello123 hello tim jason</span><span style="color: black;">woaini1 tianjianxiong333 hh aaa</span><span style="color: black;">/* 此文件用于<span style="color: black;">按照</span>bbe.txt文件对所有单词创建索引,相当于一次预处理 */ </span><span style="color: black;">ini_set(display_errors,on);</span><span style="color: black;">set_time_limit(0);</span><span style="color: black;">$file = file($src); // 数组</span><span style="color: black;">foreach($file as $i =&gt; &amp;$ls){</span><span style="color: black;"> $a = explode(" ",$ls);</span><span style="color: black;"> $len = count($a);</span><span style="color: black;"> if ($len &gt; 0){</span><span style="color: black;"> for($j=0;$i&lt;$len;$j++){</span><span style="color: black;">$data = "此单词".$a[$j]."在".($i+1)."行,".($j+1)."列";</span><span style="color: black;"> $key = md5(trim(strtolower($a[$j])));</span><span style="color: black;"> file_put_contents($key,$data);</span><span style="color: black;"> }</span><span style="color: black;"> }</span><span style="color: black;"> //echo $i.". &gt; ".$ls.&lt;br /&gt;;</span><span style="color: black;">}</span><span style="color: black;">example.php:</span><span style="color: black;">#!/usr/local/bin/php -q </span><span style="color: black;">&lt;?php</span><span style="color: black;">set_time_limit(0); </span><span style="color: black;">$getkey=empty($argv) ? $_REQUEST : $argv;</span><span style="color: black;">$arr = explode(",",$getkey); </span><span style="color: black;">$len = count($arr);</span><span style="color: black;">if($len &gt; 0){</span><span style="color: black;">for($i=0;$i&lt;$len;$i++){</span><span style="color: black;"> echo getKey($arr[$i])."\n";</span><span style="color: black;"> }</span><span style="color: black;">}</span><span style="color: black;">functuion getKey($key){</span><span style="color: black;"> $str = "<span style="color: black;">无</span>找到此单词[".$key."]";</span><span style="color: black;"> if($key){</span><span style="color: black;"> $fc = md5($key);</span><span style="color: black;"> $str = file_get_contents($fc));</span><span style="color: black;"> }</span><span style="color: black;">return $str;</span><span style="color: black;">}</span><span style="color: black;">?&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">别人的<span style="color: black;">办法</span>:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1)<span style="color: black;">运用</span>ascii码,判断字符所在范围</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2)只要扫描一遍字符<span style="color: black;">就可</span>,<span style="color: black;">繁杂</span>度为O(N)</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3)利用了php string{$i} 的特性,取字符串内任一字符</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4)todo:改为fgetc版本,<span style="color: black;">能够</span>完全不需要<span style="color: black;">运用</span>以上php特性</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">5)字符串匹配算法:http://wendell07.blog.hexun.com/14112681_d.html,<span style="color: black;">日前</span>看来最快的<span style="color: black;">办法</span>:Sunday,<span style="color: black;">因为</span>本题是单词匹配,问题更简单,只要找到头尾……</span></p><span style="color: black;">$word = $argv[<span style="color: black;">1</span>];</span><span style="color: black;">$lines = <span style="color: black;">0</span>;</span><span style="color: black;">$handle = @fopen(<span style="color: black;">"bbe.txt"</span>, <span style="color: black;">"r"</span>);</span><span style="color: black;"><span style="color: black;">if</span> ($handle) {</span><span style="color: black;"> <span style="color: black;">while</span>(!feof($handle)) {</span><span style="color: black;"> $line = fgets($handle, <span style="color: black;">4096</span>);</span><span style="color: black;"> $local = local_word($line, $word);</span><span style="color: black;"> $lines++;</span><span style="color: black;"> <span style="color: black;">if</span>( !<span style="color: black;">empty</span>($local) ){</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;">"$lines,"</span>.implode(,$local).<span style="color: black;">"\n"</span>;</span><span style="color: black;"> }</span><span style="color: black;"> }</span><span style="color: black;">fclose($handle);</span><span style="color: black;">}</span><span style="color: black;"><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">local_word</span><span style="color: black;">($line, $word)</span></span>{</span><span style="color: black;"> $local = <span style="color: black;">array</span>();</span><span style="color: black;"> $local_length = <span style="color: black;">1</span>;</span><span style="color: black;"> $word_length = strlen($word);</span><span style="color: black;"> <span style="color: black;">for</span>($i = <span style="color: black;">0</span>; ( $char = $line{$i} ) !== ; $i++ ){</span><span style="color: black;"> <span style="color: black;">// 单词最后一个字符必定不是符号,且必有一个符号结尾,此计为一个新词</span></span><span style="color: black;"> <span style="color: black;">if</span>( !is_symbel( $line{ $i<span style="color: black;">-1</span> } ) &amp;&amp; is_symbel($char) ){</span><span style="color: black;"> $local_length++;</span><span style="color: black;"> } </span><span style="color: black;"> <span style="color: black;">if</span>( $char === $word[<span style="color: black;">0</span>] &amp;&amp; <span style="color: black;">// <span style="color: black;">倘若</span><span style="color: black;">第1</span>个字符相同</span></span><span style="color: black;">is_symbel( $line{ $i<span style="color: black;">-1</span> } ) &amp;&amp; <span style="color: black;">// 且为单词<span style="color: black;">起始</span></span></span><span style="color: black;"> is_symbel( $line{ $i+$word_length }) <span style="color: black;">// 单词结尾应该为符号</span></span><span style="color: black;"> ){</span><span style="color: black;"> <span style="color: black;">// 进入验证单词模式,一个一个字符比对</span></span><span style="color: black;"> <span style="color: black;">for</span>($j = <span style="color: black;">1</span>; ($w_char = $word{$j}) !== ; $j++ ){</span><span style="color: black;"> <span style="color: black;">// 遇到单词字符不匹配</span></span><span style="color: black;"> <span style="color: black;">if</span>( $w_char != $line{ $i+$j } ){</span><span style="color: black;"> $i += $j;</span><span style="color: black;"> <span style="color: black;">break</span>;</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">// <span style="color: black;">倘若</span>单词比对完全正确</span></span><span style="color: black;"> <span style="color: black;">if</span>( $j == ($word_length<span style="color: black;">-1</span>) ){</span><span style="color: black;"> <span style="color: black;">//echo "$line_length, $word_length\n";</span></span><span style="color: black;">$local[] = $local_length;</span><span style="color: black;"> }</span><span style="color: black;"> }</span><span style="color: black;"> }</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">return</span> $local;</span><span style="color: black;">}</span><span style="color: black;"><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">is_symbel</span><span style="color: black;">($char)</span></span>{</span><span style="color: black;"> $asc = ord($char);</span><span style="color: black;"> <span style="color: black;">return</span> !( (<span style="color: black;">48</span> &lt;= $asc &amp;&amp; $asc &lt;= <span style="color: black;">57</span>) ||</span><span style="color: black;"> (<span style="color: black;">65</span> &lt;= $asc &amp;&amp; $asc &lt;= <span style="color: black;">90</span>) ||</span><span style="color: black;"> (<span style="color: black;">97</span>&lt;= $asc &amp;&amp; $asc &lt;=<span style="color: black;">122</span>) );</span><span style="color: black;">}</span><span style="color: black;"><span style="color: black;">倘若</span>你经常参加面试的话,你就会<span style="color: black;">发掘</span>几乎所有的面试开场白都是进行自我介绍,这是<span style="color: black;">由于</span>一方面面试官是刚从HR那里得到你的信息的,面试之前他可能不太<span style="color: black;">认识</span>你的<span style="color: black;">详细</span>信息,<span style="color: black;">因此</span>他<span style="color: black;">期盼</span>你<span style="color: black;">经过</span>自我介绍这个环节,<span style="color: black;">认识</span>一下你的过往经历,还有<span style="color: black;">便是</span>他利用这个时间看下你的简历。</span>经过三面、四面后几家<span style="color: black;">机构</span>等到了百度offer,<span style="color: black;"><strong style="color: blue;">下面我把面试的过程和<span style="color: black;">有些</span>面试题分享给<span style="color: black;">大众</span></strong></span>,整理的PDF目录如下:<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">说实话我并不是那种别人一看就很<span style="color: black;">爱好</span>的工程师,<span style="color: black;">由于</span><span style="color: black;">始终</span>在小<span style="color: black;">机构</span>做个小架构,<span style="color: black;">因此</span>适合我的职位范围相对<span style="color: black;">来讲</span>很窄。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">不外</span><span style="color: black;">不碍事</span>,跳出舒适区看一下其他风景,我感觉对我<span style="color: black;">来讲</span><span style="color: black;">亦</span>是一件好事。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">我<span style="color: black;">便是</span>这条街最靓滴仔!!!</span></p><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;">END<img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;">PHP开源社区<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">扫描关注&nbsp; 进入”PHP资料“</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">免费获取进阶</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">面试、文档、视频资源</p>




7wu1wm0 发表于 2024-10-22 04:46:18

感谢楼主分享,祝愿外链论坛越办越好!

7wu1wm0 发表于 2024-10-27 16:55:20

你的见解独到,让我受益匪浅,非常感谢。

qzmjef 发表于 3 天前

楼主果然英明!不得不赞美你一下!
页: [1]
查看完整版本: 2020年BAT大厂PHP工程师面试题整理(附带答案)