php为何要在linux,为什么PHP在Windows上的性能要比在linux或unix下性能低?

在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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值