PHP 程序员解决问题 8 大级别的能力

这个话题老生长谈了,在面试中必然考核的能力中,我个人认为解决问题能力是排第一位的,比学习能力优先级更高。解决问题的能力既能看出程序员的思维能力,应变能力,探索能力等,又可以看出他的经验。如果解决问题能力不佳是无法通过面试的。

这里举个例子,假如我执行了一个PHP的脚本,如php test.php,预期是可以返回一个字符串。但执行后没有任何信息输出,这时候通过什么方法能知道程序错在哪里?这里可以将解决问题能力分为8个等级,越到后面的表示能力越强。
Lv0 查看PHP错误信息
程序没有达到预期效果,证明代码出错了,看PHP的错误信息是第一步。如果直接忽略错误信息,表明这个人不适合担任专业的程序员岗位。有些情况下php.ini配置中关闭了错误显示,需要修改php.ini打开错误信息,或者错误信息被导出到了日志文件,这种情况可以直接tailf php_error.log来看错误信息。

拿到错误信息后直接定位到程序代码问题,或者到Google/百度搜索,即可解决问题。

注:打开错误显示的方法是

php.ini中display_errors / display_startup_errors 设置为On
php.ini中error_reporting 设置为E_ALL
PHP代码中设置error_reporting(E_ALL)
Lv1 存在多个版本的php或php-cli与php-fpm加载不同的配置
存在多个版本的php,懂得通过which php来看是哪个PHP,或者加绝对路径制定php版本。*阿克苏地区表示此PHPer通过了此层级的50%考验。

另外一个情况就是php-cli与php-fpm得到的执行情况不一样,如在web浏览器中执行是对的,cli下执行是错的。这时候可能是2个环境加载的php.ini不同所致。cli下通过php -i |grep php.ini得到加载了哪个php.ini。而fpm下通过phpinfo()函数可以得到php.ini的绝对路径。

Lv2 var_dump/die打印变量值信息单步调试
这是惯用的程序调试手段,也是最简单粗暴有效的解决问题方法。高级一点的手段是使用PHP的Trace类/日志类,花哨一点的可以借助phpstorm+xdebug在IDE工具里进行Debug。

Trace工具还可以分析脚本的耗时,进行PHP程序的性能优化。

这3个考验全部通过,表明此程序员已经具备了专业PHP程序员应该有的解决问题能力了。PHP程序员只要过了这个等级,就足以应多大部分情况,在中小型网站中毫无压力。

Lv3 使用strace工具跟踪程序执行
strace可以用来查看系统调用的执行,使用strace php test.php,或者strace -p 进程ID。strace就可以帮助你透过现象看本质,掌握程序执行的过程。这个手段是在大型网站,大公司里最常用的。如果没掌握strace,这里只能说抱歉了,我们不接受不会strace的PHPer。

strace其实也是对程序员基础的考验,如果不懂操作操作系统,完全不懂底层,肯定也达不到会用strace的程度。当然strace对于PHP代码里的死循环是解决不了的。比如你发现一个php-fpm进程CPU100%了,strace恐怕是解决不了的。因为strace是看系统调用,一般都是IO类操作,既然是IO密集,那CPU一定不可能是100%。

Lv4 使用tcpdump工具分析网络通信过程
tcpdump可以抓到网卡的数据通信过程,甚至数据内容也可以抓到。使用tcpdump可以看到网络通信过程是什么样的,如何时发起了TCP SYN3次握手,何时发送FIN包,何时发送RST包。这是一个基本功,如果不懂tcpdump,证明不具备网络问题解决能力。

Lv5 统计函数调用的耗时和成功率
使用xhporf/xdebug导出PHP请求的调用过程,然后分析每个函数调用的过程和耗时。能够分析PHP程序的性能瓶颈,找出可以优化的点。

另外一个对于网络服务的调用,如mysql查询,curl,其他API调用等,通过记录起始和结束时microtime,返回的是不是false,可以得到调用是否成功,耗时多少。如果可以汇总数据,整理出调用的成功率,失败率,平均延时,证明此程序员对接口质量敏感,有大型网站项目经验。

Lv6 gdb使用
gdb是C/C++调试程序的利器,需要具备一定C/C++功底的程序员才会能熟练使用gdb。上面说的strace无法跟踪php程序CPU100%,而gdb是可以跟踪的。另外gdb也可以解决php程序core dump的问题。

通过gdb -p 进程ID,再配合php-src的.gdbinit zbacktrace等工具,可以很方便地跟踪PHP程序的执行。像上面的CPU100%往往是PHP程序中发生死循环了,gdb进行多次查看,就大致可以得到死循环的位置。具备gdb解决问题能力的PHP程序员少之又少。如果能使用gdb解决PHP问题,这个PHPer百分之百可以通过面试,并且可以拿到较高的技术评级。

Lv7 查看PHP内核和扩展源码
如果能熟悉PHP内核和扩展的源码,遇到PHP程序中最复杂的内存错误,也可以有解决的能力。这类PHP程序员就是凤毛麟角了。配合gdb工具和对PHP源码的熟悉,可以查看opcode的信息,execute_data的内存,全局变量的状态等。

http://www.cere.cc/editor/attached/file/20200520/20200520225629_7073.html
http://www.cere.cc/editor/attached/file/20200520/20200520225623_6136.html
http://www.cere.cc/editor/attached/file/20200520/20200520225909_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520230101_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225701_2230.html
http://www.cere.cc/editor/attached/file/20200520/20200520225805_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225615_4886.html
http://www.cere.cc/editor/attached/file/20200520/20200520225925_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225549_3636.html
http://www.cere.cc/editor/attached/file/20200520/20200520225725_2230.html
http://www.cere.cc/editor/attached/file/20200520/20200520225957_2855.html
http://www.cere.cc/editor/attached/file/20200520/20200520230029_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225941_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225709_3323.html
http://www.cere.cc/editor/attached/file/20200520/20200520230005_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225605_2698.html
http://www.cere.cc/editor/attached/file/20200520/20200520230021_2698.html
http://www.cere.cc/editor/attached/file/20200520/20200520230037_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225829_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225933_3792.html
http://www.cere.cc/editor/attached/file/20200520/20200520225646_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225821_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225653_3167.html
http://www.cere.cc/editor/attached/file/20200520/20200520225749_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520230013_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225853_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225949_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225813_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225541_4261.html
http://www.cere.cc/editor/attached/file/20200520/20200520230109_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225733_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520230053_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520230045_3480.html
http://www.cere.cc/editor/attached/file/20200520/20200520225845_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225741_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225837_2542.html
http://www.cere.cc/editor/attached/file/20200520/20200520225557_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225901_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225637_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225917_2386.html
http://www.cere.cc/editor/attached/file/20200520/20200520225757_3480.html
http://www.cere.cc/editor/attached/file/20200520/20200520225717_2386.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225554_3577.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230001_3249.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230113_3088.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225602_2483.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225627_6075.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225642_2324.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225737_2008.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225809_2006.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230017_3248.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225833_2786.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225634_7793.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225825_2317.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225621_5763.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230010_2311.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230105_3245.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225921_2002.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225722_2165.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225914_2158.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225849_7160.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230041_3402.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225755_2163.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225931_2782.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225658_2167.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225841_2785.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225538_4360.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225729_1696.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230026_2310.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230033_3091.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225650_2792.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225954_2156.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225857_4034.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225706_2167.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225905_2002.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225745_2007.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225612_3264.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225714_2009.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225801_3569.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225946_2156.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230057_3089.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520230049_3246.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225817_1693.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225936_4188.html
http://www.ht-blue.com/kindeditor/attached/file/20200520/20200520225547_2015.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225782878287.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230193359335.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225859065906.html
http://www.lited.com/kindeditor/attached/file/20200520/2020052022550199199.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230013641364.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230073047304.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225882568256.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225921442144.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225771607160.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230068686868.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230068366836.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225741874187.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230076137613.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225812051205.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225794879487.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230068486848.html
http://www.lited.com/kindeditor/attached/file/20200520/2020052022590737737.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225816741674.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225937113711.html
http://www.lited.com/kindeditor/attached/file/20200520/2020052022570288288.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230031793179.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225759495949.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225637053705.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225564196419.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225674957495.html
http://www.lited.com/kindeditor/attached/file/20200520/2020052022570264264.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225646784678.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225932533253.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225635573557.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520230079607960.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225865236523.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225617811781.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225830113011.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225913661366.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225631473147.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225569126912.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225874617461.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225977647764.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225614371437.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225835853585.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225954435443.html
http://www.lited.com/kindeditor/attached/file/20200520/20200520225614001400.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110041_3737.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110033_3610.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105913_4438.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105601_4069.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105754_4366.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105728_3882.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105621_6253.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105816_3886.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105801_4234.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110049_3684.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105546_3535.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105849_3375.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105736_4024.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110017_6563.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105904_3973.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105841_3352.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105744_4274.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105538_8550.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105857_3186.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105945_4449.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105641_4251.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105553_5204.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105657_4277.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105833_3492.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105611_4228.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105824_4419.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105808_4393.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105936_4661.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105920_4303.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105650_3511.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110025_3626.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110057_3663.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105713_4542.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110001_3949.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110113_3475.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105930_3911.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105721_4269.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110105_3861.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520110009_3431.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105705_3277.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105634_8100.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105626_8096.html
http://www.qdc.com/kindeditor/attached/file/20200520/20200520105953_3450.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230021352135.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225943854385.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225726662666.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225757355735.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225826112611.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225621282128.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230036953695.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225994789478.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230019831983.html
http://www.scjkc.cn/uploadfile/file/20200520/2020052023000728728.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225682258225.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225780798079.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230171327132.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225670977097.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225741314131.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225830743074.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225838523852.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225521152115.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225629802980.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225911941194.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225650045004.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230032273227.html
http://www.scjkc.cn/uploadfile/file/20200520/2020052022570636636.html
http://www.scjkc.cn/uploadfile/file/20200520/2020052022590421421.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230016661666.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225524292429.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225896409640.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225715151515.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225775997599.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225940714071.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225890149014.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225846354635.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225512611261.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225692299229.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225677917791.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225754205420.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225637513751.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230077637763.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225929382938.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520230151035103.html
http://www.scjkc.cn/uploadfile/file/20200520/20200520225994849484.html

上一篇:10个典型实用的PHP代码片段


下一篇:Python与设计模式:策略模式