Back to Forum Re New

[综合] PHP关于VC9和VC6的区别以及是否线程安全的版本选择

http://blog.sina.com.cn/s/blog_70c065fe0100nn3d.html

关于VC9VC6的区别以及Thread SafeNon Thread Safe版本选择


一、如何选择PHP5.3VC9版本和VC6版本


VC6版本是使用Visual Studio 6编译器编译的,如果你的PHP是用Apache来架设的,那你就选择VC6版本。


VC9版本是使用Visual Studio 2008编译器编译的,如果你的PHP是用IIS来架设的,那你就选择VC9版本。


二、如何选择PHP5.3Thread SafeNon Thread Safe版本


Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍。


20001020日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式。


不同的是Windows系统是采用多线程的工作方式。如果在IIS下以CGI方式运行PHP会非常慢,这是由于CGI模式是建立在多进程的基础之上的,而非多线程。一般我们会把PHP配置成以ISAPI的方式来运行,ISAPI是多线程的方式,这样就快多了。但存在一个问题,很多常用的PHP扩展是以Linux/Unix的多进程思想来开发的,这些扩展在ISAPI的方式运行时就会出错搞垮IIS。因此在IISCGI模式才是PHP运行的最安全方式,但CGI模式对于每个HTTP请求都需要重新加载和卸载整个PHP环境,其消耗是巨大的。


为了兼顾IISPHP的效率和安全,微软给出了FastCGI的解决方案。FastCGI可以让PHP的进程重复利用而不是每一个新的请求就重开一个进程。同时FastCGI也可以允许几个进程同时执行。这样既解决了CGI进程模式消耗太大的问题,又利用上了CGI进程模式不存在线程安全问题的优势。


先从字面意思上理解,Thread Safe是线程安全,执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的CGI执行方式而耗尽系统资源。Non Thread Safe是非线程安全,在执行时不进行线程(Thread)安全检查。


因此,如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。


再来看PHP的两种执行方式:ISAPIFastCGI


ISAPI执行方式是以DLL动态库的形式使用,可以在被用户请求后执行,在处理完一个用户请求后不会马上消失,所以需要进行线程安全检查,这样来提高程序的执行效率,所以如果是以ISAPI来执行PHP,建议选择Thread Safe版本;


FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以FastCGI来执行PHP,建议选择Non Thread Safe版本。

EQ中文世纪地图集地址:
www.ceqmap.com
http://windows.php.net/download

Which version do I choose?

IIS
If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP.

Apache
Please use the Apache builds provided by Apache Lounge. They provide VC9, VC11 and VC14 builds of Apache for x86 and x64. We use their binaries to build the Apache SAPIs.

If you are using PHP as module with Apache builds from apache.org (not recommended) you need to use the older VC6 versions of PHP compiled with the legacy Visual Studio 6 compiler. Do NOT use VC9+ versions of PHP with the apache.org binaries.

With Apache you have to use the Thread Safe (TS) versions of PHP.

VC9, VC11 & VC14
More recent versions of PHP are built with VC9, VC11 or VC14 (Visual Studio 2008, 2012 or 2015 compiler respectively) and include improvements in performance and stability.

- The VC9 builds require you to have the Visual C++ Redistributable for Visual Studio 2008 SP1 x86 or x64 installed

- The VC11 builds require to have the Visual C++ Redistributable for Visual Studio 2012 x86 or x64 installed

- The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed

TS and NTS
TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).

What is PGO?
Profile Guided Optimization is an optimization feature available in Microsoft's Visual C++ compiler that allows you to optimize an output file based on profiling data collected during test runs of the application or module.

The x64 builds of PHP for Windows should be considered experimental, and do not yet provide 64-bit integer or large file support. Please see this post for work ongoing to improve these builds.
EQ中文世纪地图集地址:
www.ceqmap.com
Back to Forum