查找安装的 PHP 是线程安全的还是非线程安全的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5799843/
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-25 22:31:41  来源:igfitidea点击:

Find if the installed PHP is threadsafe or nonthreadsafe?

phpiisthread-safety

提问by Josh

How do I find out whether the installed version of PHP is threadsafe or not thread safe?

如何确定已安装的 PHP 版本是线程安全的还是非线程安全的?

Please note that I'm not asking the difference between a threadsafe/non thread safe installation. I would like to find out what is installed currently.

请注意,我不是在问线程安全/非线程安全安装之间的区别。我想知道当前安装了什么。

回答by grunk

Open a phpinfo() and search for the line Thread safety. For a thread-safe build you should find enable.

打开 phpinfo() 并搜索行Thread safety。对于线程安全构建,您应该找到enable

As specified in the comments by Muhammad Gelbanayou can also use:

正如Muhammad Gelbana在评论中所指定的,您还可以使用:

  • On Windows : php -i|findstr "Thread"
  • On *nix: php -i|grep Thread
  • 在 Windows 上: php -i|findstr "Thread"
  • 在 *nix 上: php -i|grep Thread

回答by Matt

If you prefer to use the command line:

如果您更喜欢使用命令行:

  • *nix:

    php -i | grep -i "Thread"
    
  • Windows:

    php -i | findstr -i "thread"
    
  • *尼克斯:

    php -i | grep -i "Thread"
    
  • 视窗:

    php -i | findstr -i "thread"
    

This should give you something like this:

这应该给你这样的东西:

Thread Safety => enabled

or

或者

Thread Safety => disabled

回答by Flemin Adambukulam

I just find it easier to look at the file named php[version].dll in the root folder of php. Its either php[version].dll or php[version]ts.dll (ts standing for Thread Safe). So, if you have php7.0.10 installed, go to the directory that has this name and you'll find a file named php7ts.dll. This is a very sad way of finding out, but it works!

我只是发现在php的根文件夹中查看名为php[version].dll的文件更容易。它是 php[version].dll 或 php[version]ts.dll(ts 代表线程安全)。因此,如果您安装了 php7.0.10,请转到具有此名称的目录,您将找到一个名为 php7ts.dll 的文件。这是一种非常可悲的发现方式,但它有效!

回答by ShiraNai7

Then there's the undocumented ZEND_THREAD_SAFEconstant, which seems to exist since PHP 4.3.

然后是未记录的ZEND_THREAD_SAFE常量,它似乎自 PHP 4.3 以来就存在。

<?php

if (ZEND_THREAD_SAFE) {
    echo 'Thread safe';
} else {
    echo 'Not thread safe';
}

https://3v4l.org/tALKX

https://3v4l.org/tALKX

回答by peroxide

Create a new PHP file and insert this code in it:

创建一个新的 PHP 文件并在其中插入以下代码:

<?php
phpinfo(); ?>

Then run this page and you will find all of the PHP information. Search for the term that you want, and it will show you it's enabled.

然后运行此页面,您将找到所有 PHP 信息。搜索您想要的术语,它会显示它已启用。

回答by Phliplip

Check if your install is Apache Module or CGI Binary. See Stack Overflow question What is thread safe or non-thread safe in PHP?.

检查您的安装是 Apache 模块还是 CGI 二进制文件。请参阅堆栈溢出问题PHP 中的线程安全或非线程安全是什么?.

回答by Elvis Ciotti

From a script:

从脚本:

/**
 * @return boolean true if PHP is thread safe
 */
function isThreadSafe()
{
    ob_start();
    phpinfo(INFO_GENERAL);
    return preg_match('/Thread\s*Safety\s*enabled/i', strip_tags(ob_get_clean()));
}