游世集

遨游人世,累文一集

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  87 随笔 :: 0 文章 :: 27 评论 :: 0 Trackbacks
      在phpchina上有朋友谈到了这个问题,由于对这个问题一直也不太清楚,所以就转一下资料。

The Challenge - PHP on Windows

尽管PHP是一个多平台语言,在Windows上运行PHP还是一个挑战。这是因为PHP是基于UNIX平台开发的,每个请求由一个不同的进程来处理。然 而在Windows平台下面,同一类型的请求是由同一进程的不同线程来处理的。这个区别意味运行着PHP的IIS的频繁崩溃。进一步来说,对这一问题的唯 一的解决方案就是把PHP运行在外部方式下(CGI)。最终导致PHP性能的降低。

Multi-threading:

PHP was originally written for a multi-process environment (Apache) and is therefore most commonly used with the popular LAMP (Linux, Apache, MySQL, PHP) platform. Under Windows, things work differently. Literally all of the Web Servers under Windows, including IIS and Apache, are multi-threaded, which means that a single process handles all concurrent clients. For PHP to run properly under a multithreaded server, it must be designed with Thread Safety in mind. Failure to do so will cause instability and may often result in unexpected crashes. To make things worse, a crash in a multithreaded environment will typically cause the entire Web Server to go down, as opposed to multi-process environment, where a typical crash will only affect one request and can generally go unnoticed.

Up until today, the only way to prevent PHP crashes on Windows was to run PHP as an external process to the Web Server via CGI.


CGI:

CGI stands for "Common Gateway Interface". CGI is a communication platform for a Web Server to speak with Web Server applications such as PHP. CGI was created as the standard interface for Web Server applications. Its main benefits are simplicity, language independence and most importantly - process isolation. This isolation prevents known bugs in PHP from crashing the Web Server. CGI also has some significant drawbacks - mainly performance. The CGI mechanism involves huge overhead resulting in poor performance caused by the initialization of a new PHP process for each request, and then its shuts down when the request is done.



Native Web Server Modules:

In response to the performance problems of CGI, several vendors have developed APIs for their servers. Well-known APIs are NSAPI from Netscape and ISAPI from Microsoft. The APIs enable PHP to run in the server process, which is persistent across all requests, saving initialization overhead. APIs are naturally used when PHP is run on a single process server, but that’s not the case for multi-threading servers. While parts of PHP were rewritten to make it thread-safe, the thread-safe version never matured to be as stable and as efficient as the multi-process version. In a nutshell, the smallest bug in PHP, one of its modules, or one of the 3rd party libraries that it uses, that causes one thread to become corrupted, can infiltrate all server threads and bring the entire server down. For that reason, implementing PHP on Windows using a native server plug-in (whether IIS or Apache) proved to be impractical, resulting in frequent, yet random crashes.

posted on 2005-12-26 09:15 xlmo 阅读(1909) 评论(4)  编辑 收藏 引用 所属分类: php

评论

# re: 为什么PHP在Windows上的性能要比在linux或unix下性能低? 2007-07-06 17:30 zxsadas
神经病,php也有isapi 模式的,cgi 模式只是其中一种

windows 本身性能就低  回复  更多评论
  

# 用windows2003+iis6.0+php平凡报IIS Worker Process遇到问题而且必须关闭" 2007-07-09 11:17 遇到相同情况
这个区别意味运行着PHP的IIS的频繁崩溃.就是啊。失败啊。  回复  更多评论
  

# re: 为什么PHP在Windows上的性能要比在linux或unix下性能低? 2008-03-04 13:26 SB
@zxsadas
弱智狗 你怎么知道的?  回复  更多评论
  

# re: 为什么PHP在Windows上的性能要比在linux或unix下性能低? 2008-03-04 13:27 SB
windows 本身性能就低
-----------------------
弱智狗 你怎么知道的? 说个理由 不然我当你吃屎了  回复  更多评论
  

只有注册用户登录后才能发表评论。