适用于 Windows 的 PHP 线程安全和非线程安全

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7204758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:15:38  来源:igfitidea点击:

PHP Thread Safe and Non-Thread Safe for Windows

phpmultithreading

提问by Sumit Gupta

I am downloading PHP for Windows. I got 2 options on the website.

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

  1. PHP Thread Safe
  2. PHP Non-Thread Safe
  1. PHP 线程安全
  2. PHP 非线程安全

Please answer the following questions:

请回答以下问题:

  1. What is the difference between the two? What are the advantages and disadvantages over one another?
  2. I am developing an e-commerce website which will have heavy traffic, which one is more recommended and why?
  1. 两者有什么区别?彼此之间有哪些优点和缺点?
  2. 我正在开发一个流量很大的电子商务网站,哪个更推荐,为什么?

回答by Crack

From PHP documentation:

来自 PHP 文档:

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.

线程安全意味着二进制文件可以在多线程网络服务器上下文中工作,例如 Windows 上的 Apache 2。线程安全的工作原理是在每个线程中创建一个本地存储副本,这样数据就不会与另一个线程发生冲突。

那我选择什么?如果您选择将 PHP 作为 CGI 二进制文件运行,那么您将不需要线程安全,因为该二进制文件在每次请求时都会被调用。对于多线程 Web 服务器,例如 IIS5 和 IIS6,您应该使用 PHP 的线程版本。

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

所以这真的取决于你想使用 PHP 的方式:

  • Apache + LoadModule: Thread Safe
  • Apache + FastCGI: Non-Thread Safe
  • IIS: Thread Safe
  • IIS + FastCGI: Non-Thread Safe
  • Apache + LoadModule:线程安全
  • Apache + FastCGI:非线程安全
  • IIS:线程安全
  • IIS + FastCGI:非线程安全

PHP manual has nice installation instructions.

PHP 手册有很好的安装说明

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

AFAIR 使用 FastCGI 运行 PHP 是更可取的方式,它执行得更快并且允许更细粒度的安全配置。

回答by Jim

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:

快速而简单:如果您使用 Apache,请编辑您的 Apache24\conf\httpd.conf 文件并搜索“loadmodule”。如果你看到你的 loadmodule 正在引用一个 .dll 类似的东西:

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"

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 enabledor TS- Thread Safe version.

然后,你想线程安全启用TS-线程安全的版本

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

否则,如果您使用带有 CGI 的 IIS 或 Apache,则使用 NTS 风格。

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.

我使用多个堆栈,并在这些多个服务器和 PHP 版本中使用,所以不要让路径 / php 或服务器版本扔给你。

回答by Saso.Filipovic

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

除了 Crack 之外,从 5.4 开始,您可以使用内置的 Web 服务器(效果很好!)。