PHP5一直以来的bug!

类别:编程语言 点击:0 评论:0 推荐:

  PHP5加入了很多新性能,这里不加多评。我只是观测到一个PHP5在windows操作系统上(尤其是2000、2003)上的一个现象:

  默认安装、配置情况下,在100个用户读取一个较大php文件的时候,在error.log文件你会发现不定期的启动信息:

[Wed Aug 25 17:59:15 2004] [notice] Apache/2.1.0-dev (Win32) PHP/5.0.2-dev configured -- resuming normal operations
[Wed Aug 25 17:59:15 2004] [notice] Server built: Aug 25 2004 16:03:58
[Wed Aug 25 17:59:15 2004] [notice] Parent: Created child process 988
[Wed Aug 25 17:59:15 2004] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 25 17:59:15 2004] [notice] Digest: done
[Wed Aug 25 17:59:15 2004] [notice] Child 988: Child process is running
[Wed Aug 25 17:59:15 2004] [notice] Child 988: Acquired the start mutex.
[Wed Aug 25 17:59:15 2004] [notice] Child 988: Starting 250 worker threads.
[Wed Aug 25 17:59:15 2004] [notice] Child 988: Starting thread to listen on port 8000.
[Wed Aug 25 17:59:15 2004] [notice] Child 988: Starting thread to listen on port 80.

  想想看:你肯定默认设置MaxRequestsPerChild=0。按照Apache2官方的说法,child process应该是永不退出才对。问题就出来了。为什么会自动重启呢?究竟是Apache2的bug还是PHP5的bug?那么继续往下看,你就会发现是什么回事。

  有了问题总需要找到解决方案。深入代码学习是一种最好的办法。PHP与Apache2的结合是php5apache2.dll文件。首先去掉php的支持,看看静态文本会不会造成同样的问题(这是一个非常愚蠢的想法)。因为Apache2本身对html文件支持是绰绰有余,而且在同类的web产品中,Apache2的这方面的性能恰恰最出众。如果要实际测试会不会出现这样的问题,那么找一个大的静态文本,远程用ab命令测试,比如:ab -n2000 -c64 -dS http://172.16.2.1。结果表明没有任何问题,就正如所推理的那样。

  结果就出来了,肯定是PHP5与Apache2的结合出了问题。找到PHP5的Apache2的handler程序。打开sapi_apache2.c。Apache2重启证明有abort产生,我们就找abort字符。果不然发现两个r->connection->aborted。同时在google上一搜索,发现类似于这样的bug report:http://bugs.php.net/bug.php?id=14542。如果不熟悉php的源代码编程,那么你直接将两个“ || r->connection->aborted”去掉,然后编译就会发现:问题解决了。

  想想整个过程,思维最为重要。往往在没有头绪的时候往往需要认真思索。

本文地址:http://com.8s8s.com/it/it28398.htm