PHP 线程安全和 Windows 非线程安全

我正在下载 PHP 的 Windows。我在网站上有2个选项。

  1. PHP 线程安全
  2. PHP 非线程安全

请回答以下问题:

  1. 这两者之间的区别是什么 优势和劣势?
  2. 我正在开发一个电子商务网站,将有繁忙的流量,哪一个是更多的建议,为什么?
90627 次浏览

From PHP documentation:

Thread Safety means that binary can work in a multithreaded webserver context, such as Apache 2 on Windows. Thread Safety works by creating a local storage copy in each thread, so that the data won't collide with another thread.

So what do I choose? If you choose to run PHP as a CGI binary, then you won't need thread safety, because the binary is invoked at each request. For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP.

So it really depends on the way that you want to use PHP:

  • Apache + LoadModule: Thread Safe
  • Apache + FastCGI: Non-Thread Safe
  • IIS: Thread Safe
  • IIS + FastCGI: Non-Thread Safe

PHP manual has nice installation instructions.

AFAIR running PHP with FastCGI is the preferable way, it performs faster and allows for more fine-grained security configuration.

In addition to Crack, since 5.4 you can use built-in web server (it works nice!).

Warning This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

Quick and simple: If you are using Apache edit your Apache24\conf\httpd.conf file and search for "loadmodule". If you see your loadmodule is referencing a .dll something like:

LoadModule php7_module "e:/x64Stack/PHP/php7.1.9/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "e:/x64Stack/PHP/php7.1.9"

Then you want Thread Safety enabled or TS - Thread Safe version.

Else if you are using IIS or Apache with CGI then NTS flavor.

I use multiple stacks and within those multiple servers and versions of PHP so don't let the paths / php or server versions throw you.